Hi All,
I'm trying to figure out how to load images from a resource file into a picture box using a visual studio windows forms application in c++. I figured out two different ways to do this in c# by going through the forums, but I cannot figure it out for c++. Here is an example of the working code in C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using System.IO;
namespace load_resource_image
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.pictureBox1.Image = Properties.Resources.another_image;
}
private void button2_Click(object sender, EventArgs e)
{
System.IO.Stream stream;
System.Reflection.Assembly assembly;
Image bitmap;
assembly = System.Reflection.Assembly.LoadFrom(Application.ExecutablePath);
stream = assembly.GetManifestResourceStream("load_resource_image.Resources.my_image2.png");
bitmap = Image.FromStream(stream);
this.pictureBox1.Image = bitmap;
}
}
}
For the first one, (button click 1) I had to add a picture into the Resources.resx file in the properties folder. For the second one I added an image called my_image2.png to the resources folder, then set the build action to embedded resource in the properties window. I tried a bunch of things that did not work in C++, and searched through forums, but was not able to find anything that works.