从多个线程渲染到单个 Bitmap 对象 [英] Rendering to a single Bitmap object from multiple threads

查看:23
本文介绍了从多个线程渲染到单个 Bitmap 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所做的是将多个位图渲染为单个位图.可能有数百张图像,渲染的位图可能超过 1000x1000 像素.

What im doing is rendering a number of bitmaps to a single bitmap. There could be hundreds of images and the bitmap being rendered to could be over 1000x1000 pixels.

我希望通过使用多个线程来加速这个过程,但由于 Bitmap 对象不是线程安全的,因此无法直接并发渲染.我的想法是将大位图分成每个 cpu 的部分,分别渲染它们,然后在最后将它们重新组合在一起.我还没有这样做,希望你们有更好的建议.

Im hoping to speed up this process by using multiple threads but since the Bitmap object is not thread-safe it cant be rendered to directly concurrently. What im thinking is to split the large bitmap into sections per cpu, render them separately then join them back together at the end. I haven't done this yet incase you guys/girls have any better suggestions.

有什么想法吗?谢谢

推荐答案

您可以使用 LockBits 并处理图像的各个部分.

You could use LockBits and work on individual sections of the image.

有关如何完成此操作的示例,您可以查看 Paint.Net 源代码,尤其是 BackgroundEffectsRenderer(是的,这是一个指向单声道分支的链接,但 Paint.Net 主代码似乎仅在 zip 文件中可用).

For an example of how this is done you can look at the Paint.Net source code, especially the BackgroundEffectsRenderer (yes that is a link to the mono branch, but the Paint.Net main code seems to be only available in zip files).

这篇关于从多个线程渲染到单个 Bitmap 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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