468,252 Members | 1,460 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,252 developers. It's quick & easy.

Embedding an image in a dll

UJ
I've got an image I want to embed in a dll to use on a screen later. I've
got it in a resource file, got it to compile in to the dll. The problem is
getting it back out. It seems like my problem is in the get resource code.

The code I'm using is:
System.Reflection.Assembly myAssembly;
myAssembly = this.GetType().Assembly;

// Creates the ResourceManager.
System.Resources.ResourceManager myManager = new
System.Resources.ResourceManager("Marlin.VisualCon trols",
myAssembly);

// Retrieves Image resource.
System.Drawing.Image myImage;
myImage =
(System.Drawing.Image)myManager.GetObject("ECSStar tupGraphic");

I can't tell whether it's the resource manager that is set up wrong or the
get object is wrong (I have a feeling the resource manager is wrong.)

The namespace that the resource is in is Marlin.VisualControls. The name of
the object is ECSStartupGraphic (I verified this through resource editor and
also by looking at the file.)

I've also added the file to the project and set it's Build Action as
Embedded Resource.

I just can't seem to get the references right.

And if I've got a window with this image on it (it will always be this
image) is there someway to tell it the file is a reference instead of trying
to look at the disk somewhere?

TIA - Jeff.
Mar 10 '06 #1
3 11375
Here's what I've cooked up:

string samplePath = "Modules.Inventory.Resources.WI_ReviewIcon.png ";

Image img = GetImageFromManifest(samplePath);
/// <summary>
/// Convert an embedded image resource to a Drawing.Image object
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public Image GetImageFromManifest(string path)
{
Image newImage = null;
try
{
Assembly thisAssembly = Assembly.GetAssembly(this.GetType());
Stream resourceStream = thisAssembly.GetManifestResourceStream(path);
newImage = Image.FromStream(resourceStream);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}
return newImage;
}

Hope that helps...

"UJ" <fr**@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I've got an image I want to embed in a dll to use on a screen later. I've
got it in a resource file, got it to compile in to the dll. The problem is
getting it back out. It seems like my problem is in the get resource code.

The code I'm using is:
System.Reflection.Assembly myAssembly;
myAssembly = this.GetType().Assembly;

// Creates the ResourceManager.
System.Resources.ResourceManager myManager = new

System.Resources.ResourceManager("Marlin.VisualCon trols", myAssembly);

// Retrieves Image resource.
System.Drawing.Image myImage;
myImage =
(System.Drawing.Image)myManager.GetObject("ECSStar tupGraphic");

I can't tell whether it's the resource manager that is set up wrong or the
get object is wrong (I have a feeling the resource manager is wrong.)

The namespace that the resource is in is Marlin.VisualControls. The name
of the object is ECSStartupGraphic (I verified this through resource
editor and also by looking at the file.)

I've also added the file to the project and set it's Build Action as
Embedded Resource.

I just can't seem to get the references right.

And if I've got a window with this image on it (it will always be this
image) is there someway to tell it the file is a reference instead of
trying to look at the disk somewhere?

TIA - Jeff.

Mar 10 '06 #2
UJ
That worked great. Thanks. I think my main problem was not knowing the name
of the item to use but I figured it.

Jeff.

"sklett" <sk****@mddirect.com> wrote in message
news:OM**************@TK2MSFTNGP11.phx.gbl...
Here's what I've cooked up:

string samplePath = "Modules.Inventory.Resources.WI_ReviewIcon.png ";

Image img = GetImageFromManifest(samplePath);
/// <summary>
/// Convert an embedded image resource to a Drawing.Image object
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public Image GetImageFromManifest(string path)
{
Image newImage = null;
try
{
Assembly thisAssembly = Assembly.GetAssembly(this.GetType());
Stream resourceStream = thisAssembly.GetManifestResourceStream(path);
newImage = Image.FromStream(resourceStream);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}
return newImage;
}

Hope that helps...

"UJ" <fr**@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I've got an image I want to embed in a dll to use on a screen later. I've
got it in a resource file, got it to compile in to the dll. The problem
is getting it back out. It seems like my problem is in the get resource
code.

The code I'm using is:
System.Reflection.Assembly myAssembly;
myAssembly = this.GetType().Assembly;

// Creates the ResourceManager.
System.Resources.ResourceManager myManager = new

System.Resources.ResourceManager("Marlin.VisualCon trols", myAssembly);

// Retrieves Image resource.
System.Drawing.Image myImage;
myImage =
(System.Drawing.Image)myManager.GetObject("ECSStar tupGraphic");

I can't tell whether it's the resource manager that is set up wrong or
the get object is wrong (I have a feeling the resource manager is wrong.)

The namespace that the resource is in is Marlin.VisualControls. The name
of the object is ECSStartupGraphic (I verified this through resource
editor and also by looking at the file.)

I've also added the file to the project and set it's Build Action as
Embedded Resource.

I just can't seem to get the references right.

And if I've got a window with this image on it (it will always be this
image) is there someway to tell it the file is a reference instead of
trying to look at the disk somewhere?

TIA - Jeff.


Mar 10 '06 #3
Hi,

"UJ" <fr**@nowhere.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
That worked great. Thanks. I think my main problem was not knowing the
name of the item to use but I figured it.


You need to use the complete name of the object, including the namespace
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Mar 10 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by D. Yates | last post: by
4 posts views Thread by Marc Pelletier | last post: by
7 posts views Thread by David Thielen | last post: by
reply views Thread by shg | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.