Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2007

Tip: Looking for answers? Try searching our database.

Embedded image in a Class Library

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Carlos Sosa Albert - 29 Oct 2007 20:45 GMT
Hello guys,

C#, VS2005: I'm trying to send an email containing an image.
I use "new AlternateView(imgStream, Mime.MediaTypeNames.Image.Gif);" to do
so, fine.

The problem is before this, when I try to create the Strem (imgStream) from
an embedded resource (myImage) I have in a resource file (myResources.resx).

I tried this code but it always returns "null", if you have any idea, will
be pretty welcome!

Stream imgStream =
Assembly.GetExecutingAssembly().GetManifestResourceStream("myNameSpace.myLibrary.myResources.myImage");

Thanks.

Signature

____________________________
Carlos Sosa Albert

Andrew Faust - 30 Oct 2007 02:35 GMT
That's because you're asking for the resource from the executing assembly.
The executing assembly is NOT your dll. It's the program that is calling
your dll. From within your dll you should be able to access your resource
directly by name without the Assembly.* stuff. So to use your example you
can call myResources.myImage directly. It will return it as a byte array,
but at that point it's trivial to create a MemoryStream object that
references it.

Signature

Andrew Faust
andrew[at]andrewfaust.com
http://www.andrewfaust.com

> Hello guys,
>
[quoted text clipped - 16 lines]
>
> Thanks.
Carlos Sosa Albert - 30 Oct 2007 14:50 GMT
Thanks for your reply, Andrew!

I can get to the bitmap using myAssembly.myResources.myImage as a
System.Drawing.Bitmap
But that's all I can get... I didn't find a way to get the byte[], and much
less a stream out of it...

Signature

____________________________
Carlos Sosa Albert

> That's because you're asking for the resource from the executing assembly.
> The executing assembly is NOT your dll. It's the program that is calling
[quoted text clipped - 24 lines]
> >
> > Thanks.
Carlos Sosa Albert - 30 Oct 2007 15:01 GMT
I found it. You pointed me in the right direction mentioning MemoryStream,
and now it works:

Stream imgStream = new MemoryStream();
MyResources.MyImage.Save(imgStream, System.Drawing.Imaging.ImageFormat.Gif);

Thanks a lot!

Signature

____________________________
Carlos Sosa Albert

> That's because you're asking for the resource from the executing assembly.
> The executing assembly is NOT your dll. It's the program that is calling
[quoted text clipped - 24 lines]
> >
> > Thanks.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.