string bmpName = "WindowsApplication6.sync.bmp"; // WindowsApplication6 corresponds to Default Namespace in your project settings.
System.IO.Stream strm = null;
try
{
strm = this.GetType().Assembly.GetManifestResourceStream(bmpName);
pictureBox1.Image = new Bitmap(strm);
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
if(strm != null)
strm.Close();
}
System.IO.Stream strm = null;
try
{
strm = this.GetType().Assembly.GetManifestResourceStream(bmpName);
pictureBox1.Image = new Bitmap(strm);
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
if(strm != null)
strm.Close();
}
ResourceWriter rw=new ResourceWriter("sample.resources");
Bitmap b=new Bitmap("shy.gif");
rw.AddResource("flag",b);
rw.Generate();读取资源:
ResourceManager rm=new ResourceManager("sample",System.Reflection.Assembly.GetExecutingAssembly());
Bitmap b=(Bitmap)rm.GetObject("flag");
this.pictureBox1.Image=b;