请教如何输出资源文件中的图片对象

luoxp520 2008-11-18 05:38:19
请教如何输出资源文件中的图片对象
例如调用
global::WindowsApplication.Properties.Resources._4;
就是GetBitmap(4)

public Image GetBitmap(string sId)
{
//System.ComponentModel.ComponentResourceManager resourceManager = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
////ResourceManager resourceManager = new ResourceManager("WindowsApplication", this.GetType().Assembly);
//Bitmap bitmap = (System.Drawing.Bitmap)(resourceManager.GetObject("_"+sId));
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
Image image = ((System.Drawing.Image)(resources.GetObject("_" + sId)));
return image;
}
...全文
131 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
luoxp520 2008-11-19
  • 打赏
  • 举报
回复
查考http://hi.baidu.com/mnmatech/blog/item/51608eb1bf296a540923029d.html

public Image GetBitmap(string sId)
{
Assembly asm = Assembly.GetExecutingAssembly();
string sResourceName = "WindowsApplication.images." + sId + ".jpg";
Stream sFile = asm.GetManifestResourceStream(sResourceName);
Image img = Image.FromStream(sFile);
return img;

}
luoxp520 2008-11-19
  • 打赏
  • 举报
回复
请教生成的资源文件

internal static System.Drawing.Bitmap _10 {
get {
object obj = ResourceManager.GetObject("_10", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
文件名就是_10.jpg
fiendloop 2008-11-18
  • 打赏
  • 举报
回复
另,可以使用GUI,把需要显示图片的控件设置为画布,把图片画上去,类似登陆验证码的做法.
当然,如果图片大了时间就长了.
fiendloop 2008-11-18
  • 打赏
  • 举报
回复
这个需要能读取图片的控件,.net2003下可以,2005好象不行
如果一定要做,可以生成一个图片文件(Image类下就有),然后读取这个图片的路径.
你的这个思路是用时间换空间的做法,能够节约一定的空间,但是要消耗不少时间.
如果服务器够用,建议存放图片直接读取图片路径.用空间换时间比较好点.

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧