C#读取资源文件的图片

IO.Stream strm = GetType().Assembly.GetManifestResourceStrea
img = new Bitmap(Image.FromStream(strm), width, height);
strm.Close();
如果是通过项目属性->资源嵌入,直接这样以用就可以了(假设资源名字叫MyBmp):
btnClose.Image =(Bitmap)Bitmap.FromStream(this.GetType().Assembly.GetManifestResourceStrea
范例:
首先在项目里先开一个Form窗体..并且加入一个图片文件...
并且将图片文件→属性→建置动作→改成"内嵌资源",如下图所示:
C# Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;//要记得using
namespace WindowsApplication1
{
public partial class GetResourceStream : Form
{
public GetResourceStream()
{
InitializeComponent();
}
private void GetResourceStream_Load(object sender, EventArgs e)
{
Assembly asm = Assembly.GetExecutingAssembly();
string name = asm.GetName().Name;
Bitmap bmp = new Bitmap(asm.GetManifestResourceStream(name ".f6.jpg"));//加载图片资源
this.pictureBox1.Image = bmp;
}
}
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;//要记得using
namespace WindowsApplication1
{
public partial class GetResourceStream : Form
{
public GetResourceStream()
{
InitializeComponent();
}
private void GetResourceStream_Load(object sender, EventArgs e)
{
Assembly asm = Assembly.GetExecutingAssembly();
string name = asm.GetName().Name;
Bitmap bmp = new Bitmap(asm.GetManifestResourceStream(name ".f6.jpg"));//加载图片资源
this.pictureBox1.Image = bmp;
}
}
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898

扫一扫加作者微信


版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网