icons and bitmaps

  • Thread starter Thread starter Analizer1
  • Start date Start date
A

Analizer1

I would like to place some icons and small bitmaps in a dll, but im not sure
how to go about this using c#

any Suggestions Welcome
thanks
 
Analizer1 said:
I would like to place some icons and small bitmaps in a dll, but im
not sure how to go about this using c#

Add the files to your project and change the Build Action property for
each file to "Embedded Resource".

You can access them in code using Assembly.GetManifestResourceStream.

Eq.
 
Where can i Find a Example...
Ive not used Assembly before

thanks
 
Analizer1 said:
[icons and bitmaps in a DLL]
Where can i Find a Example...
Ive not used Assembly before

Well, here is a quick example if you just want to retrieve a bitmap. If
it's not enough, you should check the Visual Studio documentation and
also make sure you know about the Stream class.

using System.Reflection;
.. . .
Bitmap b = (Bitmap) Bitmap.FromStream(
Assembly.GetExecutingAssembly().GetManifestResourceStream(
"MyNamespace.MyImageFilename.bmp"
));

This works if your code is in a namespace "MyNamespace" and you've added
a file "MyImageFilename.bmp" with Build Action set to "Embedded
Resource".

Eq.
 
below is code i have working....
What if the icon/image is stored in another dll
How would i go about retrieving that icon/image
Assembly assembly = Assembly.GetExecutingAssembly();

// Retrieve a list of resource names contained by the assembly.

string[] resourceNames = assembly.GetManifestResourceNames();

foreach (string resourceName in resourceNames)

{

Console.WriteLine(resourceName);

}


// Retrieving an image resource follows the same principle.

string ResourceName = string.Format("{0}.{1}", assembly.GetName().Name,
"STOP.ICO");

Console.WriteLine(ResourceName);

using(Stream barStream = assembly.GetManifestResourceStream(ResourceName))
//barResourceName)))

{


using (Icon oIcon = new Icon(barStream))

{

Bitmap oBitmap = oIcon.ToBitmap();

this.pictureBox1.Image = oBitmap;

}

}

Paul E Collins said:
Analizer1 said:
[icons and bitmaps in a DLL]
Where can i Find a Example...
Ive not used Assembly before

Well, here is a quick example if you just want to retrieve a bitmap. If
it's not enough, you should check the Visual Studio documentation and also
make sure you know about the Stream class.

using System.Reflection;
. . .
Bitmap b = (Bitmap) Bitmap.FromStream(
Assembly.GetExecutingAssembly().GetManifestResourceStream(
"MyNamespace.MyImageFilename.bmp"
));

This works if your code is in a namespace "MyNamespace" and you've added a
file "MyImageFilename.bmp" with Build Action set to "Embedded Resource".

Eq.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top