|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Embedding an image in a dllgot 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.VisualControls", myAssembly); // Retrieves Image resource. System.Drawing.Image myImage; myImage = (System.Drawing.Image)myManager.GetObject("ECSStartupGraphic"); 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. 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... Show quoteHide quote "UJ" <f***@nowhere.com> wrote in message news:%23EFivPGRGHA.1688@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.VisualControls", myAssembly); > > // Retrieves Image resource. > System.Drawing.Image myImage; > myImage = > (System.Drawing.Image)myManager.GetObject("ECSStartupGraphic"); > > 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. > > That worked great. Thanks. I think my main problem was not knowing the name
of the item to use but I figured it. Jeff. Show quoteHide quote "sklett" <skl***@mddirect.com> wrote in message news:OMa1fZGRGHA.2300@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" <f***@nowhere.com> wrote in message > news:%23EFivPGRGHA.1688@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.VisualControls", myAssembly); >> >> // Retrieves Image resource. >> System.Drawing.Image myImage; >> myImage = >> (System.Drawing.Image)myManager.GetObject("ECSStartupGraphic"); >> >> 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. >> >> > > Hi,
"UJ" <f***@nowhere.com> wrote in message You need to use the complete name of the object, including the namespacenews:%23KLaOGHRGHA.196@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. -- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
Other interesting topics
Increase all digits in a number(string) one step
Anonymous Methods As ThreadStarts Sockets, to be continued... C# Books Refering to Object Members in A Collection in an ASP.NET BoundColu finding the current user name accessing an ASP.NET page Form Minimize What is wrong with this Producer-Consumer sample? Adding a button click event to my Main function Using a Class Library Settings File in ASP.NET 2.0 |
|||||||||||||||||||||||