保存图片框图像时出现问题 [英] problem in saving picturebox image
问题描述
然后,当我想检索图像并将其显示在图片框中时,我使用此方法:
公共 静态图片CreateImage( byte [] imageData)
{
图片image = 空;
如果(图像数据!= 空)
{
使用(MemoryStream inStream = 新 MemoryStream())
{
inStream.Write(imageData, 0 ,imageData.Length);
图片= Bitmap.FromStream(inStream);
}
}
返回图片;
}
但是当我想使用以下代码将从数据库中检索到的图像保存在磁盘上时:
如果(pictueBox1.Image!= 空)
{
pictueBox1.Image.Save( @" ,ImageFormat.Jpeg);
}
它给出了一个错误:
System.Drawing.dll中发生了类型为"System.Runtime.InteropServices.ExternalException"的未处理异常
附加信息:GDI +中发生一般错误.
当我从磁盘而不是从数据库中加载图像时,也不会发生此错误.
保存文件需要您的应用对当前文件夹具有写权限-包含当前网页的文件夹.设置一个单独的文件夹来保存它们,并向所有用户授予写权限.
如果您没有写权限,那么GDI +会给出错误.
hi
i store an image in sql server file(sdf file) by changing it to an array of bytes,
then when i want to retrive the image and show it in the picture box, i use this method:
public static Image CreateImage(byte[] imageData)
{
Image image=null;
if(imageData !=null)
{
using (MemoryStream inStream = new MemoryStream())
{
inStream.Write(imageData, 0, imageData.Length);
image = Bitmap.FromStream(inStream);
}
}
return image;
}
but when i want to save the image retrived from database on the disk with this code:
if (pictueBox1.Image != null)
{
pictueBox1.Image.Save(@"pic3.jpg", ImageFormat.Jpeg);
}
it gives an error :
An unhandled exception of type ''System.Runtime.InteropServices.ExternalException'' occurred in System.Drawing.dll
Additional information: A generic error occurred in GDI+.
also this error doesn''t happen when i load image from disk instead of database
Saving the file requires that your app has write permission on the current folder - the folder containing the current web page. Set up a separate folder to hold them, and give write permission to all users.
If you don''t have write permission, then GDI+ will give an error.
这篇关于保存图片框图像时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!