关于GDI+一般性错误

2013/08/12

出问题的代码:
private bool DevideImageIngnoreHalfWord(List<Image> bmpList, Size wndSize, out List<Image> newBmpList)
        {
            newBmpList = new List<Image>();
            for (int i = 0; i < bmpList.Count; i++)
            {
                Bitmap bmpToWnd = new Bitmap(bmpList[i], new Size(wndSize.Width, bmpList[i].Height));
                int bmpCount = 0;
                int lastBmpHeight = 0;
                int curBmpPosY = 0;
                Size safeSize = new Size(0, 0);
                Bitmap newBitmap;
                bmpCount = bmpToWnd.Height / wndSize.Height;
                lastBmpHeight = bmpToWnd.Height % wndSize.Height;
                if (bmpCount == 0)
                {
                    newBitmap = new Bitmap(bmpToWnd);
                    if (!IsBmpHaveNoContent(newBitmap))
                    {
                        newBmpList.Add(newBitmap);
                    }
                    else
                    {
                        if (newBitmap != null)
                        {
                            newBitmap.Dispose();
                            newBitmap = null;
                        }
                    }
                    if (bmpToWnd != null)
                    {
                        bmpToWnd.Dispose();
                        bmpToWnd = null;
                    }
                    continue;
                }
                for (int j = 0; j < bmpCount; j++)
                {
                    newBitmap = new Bitmap(wndSize.Width, wndSize.Height);
                    Graphics gNewBmp = Graphics.FromImage(newBitmap);
                    Point point = new Point(0, curBmpPosY);
                    gNewBmp.DrawImage(bmpToWnd, 0, 0, new Rectangle(point, wndSize), GraphicsUnit.Pixel);
                    if (!IsBmpHaveNoContent(newBitmap))
                    {
                        newBmpList.Add(newBitmap);
                    }
                    else
                    {
                        if (newBitmap != null)
                        {
                            newBitmap.Dispose();
                            newBitmap = null;
                        }
                    }
                    curBmpPosY += wndSize.Height;
                    if (gNewBmp != null)
                    {
                        gNewBmp.Dispose();
                        gNewBmp = null;
                    }
                }
                if (lastBmpHeight > 0)
                {
                    newBitmap = new Bitmap(wndSize.Width, lastBmpHeight);
                    Graphics gNewBmp = Graphics.FromImage(newBitmap);
                    Point point = new Point(0, curBmpPosY);
                    Size size = new Size(wndSize.Width, lastBmpHeight);
                    gNewBmp.DrawImage(bmpToWnd, 0, 0, new Rectangle(point, size), GraphicsUnit.Pixel);
                    if (!IsBmpHaveNoContent(newBitmap))
                    {
                        newBmpList.Add(newBitmap);
                    }
                    else
                    {
                        if (newBitmap != null)
                        {
                            newBitmap.Dispose();
                            newBitmap = null;
                        }
                    }
                    if (gNewBmp != null)
                    {
                        gNewBmp.Dispose();
                        gNewBmp = null;
                    }
                }
                if (bmpToWnd != null)
                {
                    bmpToWnd.Dispose();
                    bmpToWnd = null;
                }
            }
            return true;
        }

异常信息:
Exception:A generic error occurred in GDI+.
System.Runtime.InteropServices.ExternalException
Stack Trace:
   at System.Drawing.Graphics.Clear(Color color)
   at System.Drawing.Bitmap..ctor(Image original, Int32 width, Int32 height)
   at System.Drawing.Bitmap..ctor(Image original)
   at Nova.Rss.RssToImage.DevideImageIngnoreHalfWord(List`1 bmpList, Size wndSize, List`1& newBmpList)
重要参考资料:
http://support.microsoft.com/kb/814675/zh-cn
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值