IImage, PNGs, Alpha Blending and Embed Resources

J

jonfroehlich

I have a fair amount of .png graphic files that I use for image buttons
and other widgets in a .NET CF library that I'm developing. I'm
wondering what the best way is to organize them. I've read previous
posts by others debating the benefits of embedded resources versus
loading them from the disk directly. Given that I'm developing a
library, it would certainly be easier, I believe, if my graphic files
were embedded into the .dll itself. That way, developers wouldn't have
to copy over a lingering resource directory when they wanted to use the
dll. However, I currently load my pngs as IImage objects via
OpenNetCF's ImageFactory.CreateImageFromFile(). This allows me to draw
the pngs with alpha blending. So, my question is, is there an easy way
to load pngs as IImage objects when they are stored as an embedded
resource?

I thought I could do something like:

IImage img;
Stream stream =
Assembly.GetExecutingAssembly().GetManifestResourceStream("my.png"));
new ImagingFactory().CreateImageFromStream(stream, out img);

However, CreateImageFromStream accepts an IStream (not a
System.IO.Stream).

Thanks!
 
J

jonfroehlich

I'm gonna go ahead and answer my own question here :) I found the
StreamOnFile class in the OpenNETCF.Drawing.Imaging namespace. So, to
load embedded resource pngs as IImage objects, you simply do something
like this:

IImage img;
Stream stream =
Assembly.GetExecutingAssembly().GetManifestResourceStream("icon.png");
StreamOnFile sof = new StreamOnFile(stream);
new ImagingFactory().CreateImageFromStream(sof, out img);

Not sure if you should call stream.Close() or not after this operation.

Hope this helps someone :)
 

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

Top