I have an image in my project stored at Resources/myimage.jpg. How can I dynamically load this image into Bitmap object?
相关问题
- Views base64 encoded blob in HTML with PHP
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- How to get the background from multiple images by
- Why am I getting UnauthorizedAccessException on th
With and ImageBox named "ImagePreview FormStrings.MyImageNames contains a regular get/set string cast method, which are linked to a scrollbox type list. The images have the same names as the linked names on the list, except for the .bmp endings. All bitmaps are dragged into the resources.resx
JDS's answer worked best. C# example loading image:
pictureBox1.Image = ProjectName.Properties.Resources.ImageName;
Note the followings:
The example code line is run successfully using VisualStudio 2015 Community.
Code I use in several of my projects... It assumes that you store images in resource only as bitmaps not icons
Way easier than most all of the proposed answers
You can also save the bmp in a var like this:
hope it helps!
In my case -- I was using Icons in my resource, but I needed to add them dynamically as Images to some
ToolStripMenuItem
(s). So in the method that I created (which is where the code snippet below comes from), I had to convert the icon resources to bitmaps before I could return them for addition to myMenuItem
.Something else to be aware of, if your image/icon has spaces (" ") in its name when you add them to your resource, VS will automatically replace those spaces with "_"(s). Because, spaces are not a valid character when naming your resource. Which is why I'm using the
Replace()
method in my referenced code. You can likely just ignore that line.