问题描述
Imageimg1=((System.Drawing.Image)(resources.GetObject("Image1")));用这种方式会出现NotSupported错误,正确写法是在FormLoad里对于Bitmap图片publicstaticBitmapShowBitmap(stringfileName){Assemblyasm=Assembly.GetExecutingAssembly();Streamstream=null;BitmapMyImage=null;try{stream=asm.GetManifestResourceStream(fileName);MyImage=newBitmap(stream);}catch(Exceptione){AlertForm.Show("加载图片错误:"+e.Message);}finally{if(stream!=null){stream.Close();}}returnMyImage;}对于Icon图片publicstaticIconShowIcon(stringfileName){Assemblyasm=Assembly.GetExecutingAssembly();Streamstream=null;IconMyImage=null;try{stream=asm.GetManifestResourceStream(fileName);MyImage=newIcon(stream);}finally{if(stream!=null){stream.Close();}}returnMyImage;}然后就可以使用了。
解决方案
时间: 2024-10-26 12:10:49