用GDI +叠加图像 [英] overlaying images with GDI+

查看:126
本文介绍了用GDI +叠加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一张图片与其他几张图片叠加在一起.我使用以下代码来做到这一点:

I'm trying to overlay a image with a couple of other images. I use this code to do that:

Dim gbkn As Bitmap = New Bitmap(7001, 7001, Imaging.PixelFormat.Format32bppArgb)
Dim g As Graphics = Graphics.FromImage(CType(gbkn, Image))
g.DrawImage(Image.FromFile("C:\background.png"), New Point(0, 0))
g.DrawImage(Image.FromFile("C:\firstlayer.png"), New Point(0, 0))
g.DrawImage(Image.FromFile("C:\secondlayer.png"), New Point(0, 0))

这适用于前两张图片.之后,将引发OutOfMemoryException. 我意识到图像很大. 但是难道不可以做覆盖物并将它们放在某个地方吗?

This works with the first two pictures. After that an OutOfMemoryException is thrown. I realize the size of the images are large. But isn't it somehow possible to do the overlays and chache them somewhere?

即使将第一个叠加层的结果保存到磁盘,释放内存并添加另一层,我仍然会遇到异常.

Even if I save the result of the first overlay to disk, free memory, and add another layer I still get the exception.

我应该如何解决这个问题?

How should I approach this problem?

JosP

推荐答案

不知道这是否确实是问题所在,但是您不会丢弃在位图上绘制的图像.这有帮助吗?

Don't know if this is actually the problem, but you are not disposing of the images that you are drawing on the bitmap. Does this help?

Dim gbkn As Bitmap = New Bitmap(7001, 7001, Imaging.PixelFormat.Format32bppArgb)
Dim g As Graphics = Graphics.FromImage(CType(gbkn, Image))
Dim img As Image = Image.FromFile("C:\background.png")
g.DrawImage(img, New Point(0, 0))
img.Dipose()
img As Image = Image.FromFile("C:\firstlayer.png")
g.DrawImage(img, New Point(0, 0))
img.Dispose()
img As Image = Image.FromFile("C:\secondlayer.png")
g.DrawImage(Image.FromFile("C:\secondlayer.png"), New Point(0, 0))
img.Dispose()

我严重怀疑它与图像有关,因为我处理的图像大小是其大小的2-3倍而没有问题.同样,OutOfMemoryError异常似乎是< sarcasm>极其有用的</sarcasm>之一. GDI抛出的错误通常与内存无关.

I seriously doubt it has anything to do with the images, as I have worked with images 2-3 times that size without that problem. Also OutOfMemoryError exception seems to be one of the <sarcasm>extremely useful</sarcasm> errors that GDI throws that frequently has nothing to do with memory.

这篇关于用GDI +叠加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆