It's very easy to mark an image file to become an embedded resource however how does one access the image thereafter. Please can I have some example code?
views:
1092answers:
4
+1
A:
Look at the third code snippet at http://msdn.microsoft.com/en-us/library/aa309403(VS.71).aspx
Franci Penov
2008-09-30 18:14:22
+1
A:
The most direct method:
YourProjectsBaseNamespace.Properties.Resources.YourImageResourceName
Will
2008-09-30 18:15:38
+2
A:
1) Adding and Editing Resources (Visual C#)
System.Drawing.Bitmap bitmap1 = myProject.Properties.Resources.Image01;
2) Accessing Embedded Resources using GetManifestResourceStream
Assembly _assembly = Assembly.GetExecutingAssembly();
Stream _imageStream =
_assembly.GetManifestResourceStream(
"ThumbnailPictureViewer.resources.Image1.bmp");
Bitmap theDefaultImage = new Bitmap(_imageStream);
Gulzar
2008-09-30 18:15:56
And, of course, you'd put a using statement around that Stream declaration...
bdukes
2008-09-30 18:24:43
@bdukes: Not necessarily. Not sure how the `Bitmap` class works, but if it's like the `Image` class you can't dispose the stream until you are done with the image. And then you should dispose the image, not the stream. (At least if I have understood the documentation correctly :)
Svish
2010-03-09 08:58:04
A:
//Get the names of the embedded resource files;
List<string> resources = new List<string>(AssemblyBuilder.GetExecutingAssembly().GetManifestResourceNames());
//Get the stream
StreamReader sr = new StreamReader(
AssemblyBuilder.GetExecutingAssembly().GetManifestResourceStream(
resources.Find(target => target.ToLower().Contains("insert name here"))
You can convert from bitmap from the stream. The Bitmap class has a method that does this. LoadFromStream if my memory serves.
Leahn Novash
2008-09-30 18:18:17