苏飞论坛

标题: 今天解决了一个图片缩略图报“A generic error occurred in GDI+”错误的问题 [打印本页]

作者: 站长苏飞    时间: 2013-8-14 08:46
标题: 今天解决了一个图片缩略图报“A generic error occurred in GDI+”错误的问题
      今天解决了一个图片缩略图报“A generic error occurred in GDI+”错误的问题
今天写了一个关于生成缩略图片的功能
方法如下
[C#] 纯文本查看 复制代码
/// <summary>
    /// 得到图片缩略图
    /// </summary>
    /// <param name="img">图片对象</param>
    /// <param name="maxWidth">最大宽度</param>
    /// <param name="maxHeight">最大高度</param>
    /// <returns></returns>
    public static System.Drawing.Image GetThumbImage(System.Drawing.Image img, int maxWidth, int maxHeight, bool isBlock, out float size)
    {
        int tWidth;
        int tHeight;
        size = 1;

        if (!isBlock)
        {
            tWidth = maxWidth;
            tHeight = maxHeight;
        }
        else
        {
            if (!(maxHeight > img.Height && maxWidth > img.Width))
            {
                float HeightMultipier = (float)maxHeight / (float)img.Height;
                float WidthMultipier = (float)maxWidth / (float)img.Width;
                if (HeightMultipier > 1) HeightMultipier = 1;
                if (WidthMultipier > 1) WidthMultipier = 1;
                float SizeMultiplier = WidthMultipier < HeightMultipier ? WidthMultipier : HeightMultipier;
                size = SizeMultiplier;
                tWidth = (int)(img.Width * SizeMultiplier);
                tHeight = (int)(img.Height * SizeMultiplier);
            }
            else
            {
                tWidth = img.Width;
                tHeight = img.Height;
            }
        }
        System.Drawing.Image bitmap = new System.Drawing.Bitmap(tWidth, tHeight);
        //新建一个画板
        Graphics g = System.Drawing.Graphics.FromImage(bitmap);
        //设置高质量插值法
        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
        //设置高质量,低速度呈现平滑程度
        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        //清空画布并以透明背景色填充
        g.Clear(Color.Transparent);
        //在指定位置并且按指定大小绘制原图片的指定部分
        g.DrawImage(img, new Rectangle(0, 0, tWidth, tHeight),
            new Rectangle(0, 0, img.Width, img.Height),
            GraphicsUnit.Pixel);
        return bitmap;
    }

在本地测试的好好的,上传到服务器就出问题,
错误如下
(, 下载次数: 265)