无法在 GDI 上绘图+ 位图对象
我正在用 c++ gdi gdi+ 编写程序。 使用 gdi+ api 在 gdi+ 位图上绘制大图像很慢。 所以我使用了以下方式来绘制:
Bitmap img(xxx);
Graphics gr(&img);
HDC dc = gr.GetHDC();
::StretchDIBits(
dc,
rec.left, rec.top,
(rec.right - rec.left), (rec.bottom - rec.top),
m_recRegin.left , m_recRegin.top,
m_recRegin.right - m_recRegin.left, m_recRegin.bottom - m_recRegin.top,
XXX, XXX, DIB_RGB_COLORS, SRCCOPY);
gr.ReleaseHDC(dc);
这段代码运行完美一段时间。 但是,当系统范围的池已满时,会创建大量具有大尺寸 CBitmap 的兼容 DC。 似乎无法在位图上绘制任何东西。
发生了什么? 在图形上绘图。
当这部分代码失败时,我仍然可以使用 GDI+ API GetLastError() return 8.
非常感谢!
I am writing program in c++ gdi gdi+.
Drawing large image on gdi+ bitmap is slow is using gdi+ api.
So I used the following way to draw:
Bitmap img(xxx);
Graphics gr(&img);
HDC dc = gr.GetHDC();
::StretchDIBits(
dc,
rec.left, rec.top,
(rec.right - rec.left), (rec.bottom - rec.top),
m_recRegin.left , m_recRegin.top,
m_recRegin.right - m_recRegin.left, m_recRegin.bottom - m_recRegin.top,
XXX, XXX, DIB_RGB_COLORS, SRCCOPY);
gr.ReleaseHDC(dc);
this code run perfectly some time.
But when the system-wide pool is full by creating lots of compatibleDCs with large size of CBitmap. It seems can not draw any thing on the Bitmap.
What happened? when this part of code failed, I can still draw on the graphics using GDI+ APIs
GetLastError() return 8.
Many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
8 是“没有足够的存储空间来处理此命令。”
因此,您的 GDI 存储空间不足,无法用于执行
::StretchDIBits
。将来,您可以使用以下命令从命令行查找 Windows 错误:
net helpmsg <十进制错误>
。8 is "Not enough storage is available to process this command."
So you ran out of storage for GDI to use to execute
::StretchDIBits
.In the future, you can lookup Windows errors from the command line with:
net helpmsg <error in decimal>
.除了其他人所说的之外,Graphics 对象还实现了 IDisposable。 这意味着他们可能(并且实际上确实)持有有限的资源。 确保您正在调用“gr.Dispose()”或将东西放在“using”块中。 如果不这样做,将由垃圾收集器来确定对象何时完成并释放其资源。 对于资源密集型对象(例如图形)来说,这是一个不好的做法。
根据大小,位图也可能会消耗大量资源,因为它们会占用大量 RAM。 如果代码示例中使用的位图在其之后从未被引用,还要确保它们被丢弃......
In addition to what others have said, Graphics objects implement IDisposable. This means they likely (and actually do) hold onto a limited resource. Ensure you are calling "gr.Dispose()" or placing things in a "using" block. Failing to do this will leave it up to the garbage collector to determine when the objects are finalized, and their resources released. That is a bad practice for resource intensive objects-- such as Graphics.
Depending on the size Bitmaps may also be resource hungry as they can eat a lot of RAM. If the bitmaps used in your code sample are never referenced after it, also ensure they're getting disposed of...