I am working on the C#/Windows Forms project. Currently I am displaying
images using Bitmap objects that I create at runtime from .jpg files. It
means that I have to distribute all .jpg files with the application. Is
there a way to incorporate .jpg images at design time, so I won't have to
redistribute them?
Gregory Khrapunovich
You can add each jpg to your project and set there Build Action to Embedded
Resource. This way the jpg will be embedded in the output assembly and you
can load each jpg when needed using the GetManifestResourceStream method.
Note that this assumes that you're using VS.NET 2003. In VS 2005 you can
could use the project properties and the resulting strongly typed resource
access that it creates.

Signature
Tim Wilson
.NET Compact Framework MVP
> I am working on the C#/Windows Forms project. Currently I am displaying
> images using Bitmap objects that I create at runtime from .jpg files. It
> means that I have to distribute all .jpg files with the application. Is
> there a way to incorporate .jpg images at design time, so I won't have to
> redistribute them?
> Gregory Khrapunovich
Bajoo - 11 Nov 2005 06:48 GMT
Dear Gregory,
After you have change the files to Embedded
resource, you can get the image by using the following code
Assembly myAssembly = Assembly.GetExecutingAssembly();
Stream myStream =
myAssembly.GetManifestResourceStream("ABC.XYZ.Resource." +
ImageMap[buttonCaption].ToString());
Image image = new Bitmap(myStream);
I hope it helps
Regards,
Naveed Ahmad Bajwa
http://bajoo.blogspot.com/
Bajoo - 11 Nov 2005 08:02 GMT
Dear Gregory,
After you have change the files to Embedded
resource, you can get the image by using the following code
Assembly myAssembly = Assembly.GetExecutingAssembly();
Stream myStream =
myAssembly.GetManifestResourceStream("ABC.XYZ.Resource." +
ImageMap[buttonCaption].ToString());
Image image = new Bitmap(myStream);
I hope it helps
Regards,
Naveed Ahmad Bajwa