1) Embedded Resource (Build Action set to Embedded Resource) uses GetManifestResourceStream read at run time
Image.fromstream (assembly.getexecutingassembly (). GetManifestResourceStream ("WindowsFormsApplication1.Properties.Resources.warning.png"));
2) Resource (Build Action set to Resource) is read at run time using Resource Manager
ResourceManager rm = new ResourceManager ("Windowsformsapplication1.g", typeof (Form1). Assembly);
Image warimg = null;
ResourceSet rs= RM. GetResourceSet (New System.Globalization.CultureInfo ("en"), true,true);
foreach (DictionaryEntry item in RS)
{
Console.WriteLine (item. Key.tostring ());
warimg = Bitmap.fromstream (item. Value as Stream);
}
3) If you are adding pictures directly to. ResX resource file, read with Resource manager at run time, but read differently
ResourceManager rm = new ResourceManager ("WindowsFormsApplication1.Properties.Resources", typeof (Form1). Assembly);
Bitmap warnimg = rm. GetObject ("Warning") as Bitmap;
The above is the case under WinForm and WPF, and there is another way of embedding resources under ASP. Webresourceattribute, Note: The build action for image here must be embedded Resource.
Add assembly attribute:
[Assembly:webresourceattribute ("ServerControl1.images.component.gif", "Image/gif")]
Client reads:
String imgurl = Page.ClientScript.GetWebResourceUrl (typeof (ServerControl1), ("ServerControl1.images.component.gif" );
How to read various resource under. NET