Can anybody tell me the step-by-step on how to load an image into a PictureBox on a C++/CLI Project?
I already have 30 tabs in my browser searching for it and still couldn't figure how. I was able to use the FromFile
at least but I want the image to embed into the project as a resource image and use it.
This works for me, but not what I want:
Image^ image = Image::FromFile("C:\Resources\sample_image.png");
this->pictureBox1->Image = image;
I tried to right-click
on my project, Add New Item
> Resource
> Assembly Resource File (.resx)
and name it as TestResource
then import the image with the name of sample_image
, then I tried the following code to access and load it.
auto resourceAssembly = Reflection::Assembly::GetExecutingAssembly();
auto resourceName = resourceAssembly->GetName()->Name + ".TestResource";
auto resourceManager = gcnew Resources::ResourceManager(resourceName, resourceAssembly);
this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^>(resourceManager->GetObject(L"sample_image")));
but I'm getting an unhandled exception error:
System.Resources.MissingManifestResourceException: 'Could not find any
resources appropriate for the specified culture or the neutral
culture. Make sure "Sample Project.TestResource.resources" was
correctly embedded or linked into assembly "Sample Project" at compile
time, or that all the satellite assemblies required are loadable and
fully signed.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…