保存图片框图像时出现问题 [英] problem in saving picturebox image

查看:73
本文介绍了保存图片框图像时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我通过将图像更改为字节数组将图像存储在sql服务器文件(sdf文件)中,
然后,当我想检索图像并将其显示在图片框中时,我使用此方法:

 公共 静态图片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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆