前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【手记】解决Graphics.DrawImage带ImageAttributes在XP报内存不足的问题

【手记】解决Graphics.DrawImage带ImageAttributes在XP报内存不足的问题

作者头像
AhDung
发布2019-09-04 10:52:50
1.2K0
发布2019-09-04 10:52:50
举报
文章被收录于专栏:AhDungAhDung

异常信息:

代码语言:javascript
复制
System.OutOfMemoryException: 内存不足。
   在 System.Drawing.Graphics.CheckErrorStatus(Int32 status)
   在 System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect, Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr callbackData)
   在 System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect, Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
   在 System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect, Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr)
   ...

这个问题在外网也有一些讨论,我倾向的说法是,XP的GDI+组件存在问题,对于像素格式PixelFormat有点特别的图像,把它绘制到其它地方的时候处理不好ImageAttributes,于是引发异常。

解决思路,既然同时满足这两者会报错:

代码语言:javascript
复制
g.DrawImage(PixelFormat特别的Image, xxx, imageAttributes)

那么只要错开其一就行,比如这两种就不会报:

代码语言:javascript
复制
g.DrawImage(常规Image, xxx, imageAttributes); //方法一
g.DrawImage(PixelFormat特别的Image, xxx); //方法二,不使用imageAttributes

所以可以用方法二从原图得到一张像素格式正常的新图,然后用方法一把它画出去,就是弄个副本。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-09-03 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档