当前位置:编程学习 > C#/ASP.NET >>

[急等]GDI+ 中发生一般性错误

//图片转换的类
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.IO;

/// <summary>
/// ImageBase64Convert 的摘要说明
/// </summary>
public class ImageBase64Convert
{
public ImageBase64Convert()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
    public static string ImageToBase64String(System.Drawing.Image image)
    {
        if (image == null)
        {
            return "";
        }
        try
        {
            MemoryStream memoryStream = new MemoryStream();
            image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] array = memoryStream.GetBuffer();
            //memoryStream.Read(array, 0, array.Length);
            return Convert.ToBase64String(array);
        }
        catch
        {
            return "";
        }
    }
    public static System.Drawing.Image Base64StringToImage(string stream)
    {
        if (stream == null || stream == "")
        {
            return null;
        }
        try
        {
            MemoryStream memoryStream = new MemoryStream();
            byte[] array = Convert.FromBase64String(stream);
            memoryStream.Write(array, 0, array.Length);
            return System.Drawing.Image.FromStream(memoryStream, true, true);
        }
        catch
        {
            return null;
        }
    }
}

//调用页面
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class view_company : System.Web.UI.Page
{
    WebSalesDao wd = new WebSalesDao();
    LoginVo lv;
    DataSet ds;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            int cid = Convert.ToInt32(Request.QueryString["pid"]);
            lv = new LoginVo();
            ds = new DataSet();
            lv = (LoginVo)Session["user"];
            ds = wd.ProductDefine_GetByCompanyNo(lv, cid);
            
            if (ds != null)
            {
                DataList1.DataSource = ds;
                DataList1.DataBind();
                gvcompany.DataSource = ds;
                gvcompany.DataBind();
            }
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                string img = ds.Tables[0].Rows[i][24].ToString();
                Image image1 = (Image)gvcompany.Rows[i].FindControl("productimg");
                if (img != "")
                {
                    System.Drawing.Image image = ImageBase64Convert.Base64StringToImage(img);
                    string path = Server.MapPath(@"/websales");
                    image.Save(path + @"\pictrue\pictrue" + i.ToString() + ".jpg");
                    image1.ImageUrl = @"..\pictrue\pictrue" + i.ToString() + ".jpg";
                    image1.Height = 64;
                    image1.Width = 64;
                    image.Dispose();
                    image1.Dispose();
                }
                else
                {
                    image1.ImageUrl = @"..\pictrue\1.jpg";
                    image1.Width = 64;
                    image1.Height = 64;
                }
            }
        }
    }
}

各位大哥帮帮忙,程序可以正常运行,但用ie请求IIS的时候就会报错,断点调试没有这样的问题,IIS也设置了相应的权限,求各位高手帮帮忙
GDI+ 中发生一般性错误。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.Runtime.InteropServices.ExternalException: GDI+ 中发生一般性错误。

源错误: 


行 40:                     System.Drawing.Image image = ImageBase64Convert.Base64StringToImage(img);
行 41:                     string path = Server.MapPath(@"/websales");
行 42:                     image.Save(path + @"\pictrue\pictrue" + i.ToString() + ".jpg");
行 43:                     image1.ImageUrl = @"..\pictrue\pictrue" + i.ToString() + ".jpg";
行 44:                     image1.Height = 64;
 

源文件: d:\WebSales\view\company.aspx.cs    行: 42 

堆栈跟踪: 


[ExternalException (0x80004005): GDI+ 中发生一般性错误。]
   System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) +397778
   System.Drawing.Image.Save(String filename, ImageFormat format) +69
   System.Drawing.Image.Save(String filename) +22
   view_company.Page_Load(Object sender, EventArgs e) in d:\WebSales\view\company.aspx.cs:42
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436

 
--------------------编程问答-------------------- 行 42:                    image.Save(path + @"\pictrue\pictrue" + i.ToString() + ".jpg"); 
会在这一行报错,求大家帮帮忙 --------------------编程问答-------------------- 求解,请大家帮帮忙
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,