Delphi / C ++ Builder Windows 10 1709位图操作非常慢 [英] Delphi / C++ builder Windows 10 1709 bitmap operations extremely slow

查看:117
本文介绍了Delphi / C ++ Builder Windows 10 1709位图操作非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人遇到这个问题吗? :

Anyone experienced this problem? :

它在Windows 10更新到内部版本1709之后出现。
经过一段时间的系统运行-几个小时-,位图加载,图像列表项添加变得极其缓慢。 256x256 BMP的加载时间超过10秒...在执行此操作时,它占用了100%的一个CPU内核。
这样,通常在几秒钟内启动的已编译应用程序现在在几分钟内即可启动!

It appeared after Windows 10 update to build 1709. After some system up time - a few hours -, bitmap loadings, imagelist item adding gets extremely slow. A 256x256 BMP loads in more than 10 seconds...while doing this, it occupies one CPU core 100%. So compiled applications that start up normally in seconds now start up in minutes!

我经常使用休眠/恢复模式。
显示驱动程序已有一年以上的历史了,所以这不成问题。

I use hibernation/resume regularly. Display drivers are more than a year old, so that can't be the problem.

对此有何评论?

更新:
我发现使用Canvas.Pixels的代码会发生这种情况,因此可以更改,但它的速度却非常慢。

Update: I found that this happens with code that use Canvas.Pixels, so that can be changed, still it slowed down very much.

更新2:
替换为Scanline操作可以加快处理速度。近期的Windows修补程序一定会使Canvas.Pixels在大量使用时确实变慢。

Update 2: Replacing with Scanline operations speeded up things. Recent Windows patch must have made Canvas.Pixels really slow on larger amount use.

推荐答案


  1. GDI画布像素[x] [y] 很慢。

  1. GDI Canvas Pixels[x][y] is slow.

它执行许多检查和颜色转换您都不知道(实际上是几十个子调用,如果不是数百个)。这就是为什么它这么慢,与Win10无关。从Windows启动到现在为止,这种行为一直存在,至少是我所知 GDI 而不是 VCL (与Borland / Embarcadero VCL无关) )。因此,请勿大量使用 Pixels [x] [y] 。甚至以这种方式清除 1024x1024 图像,在某些机器上也可能只需要大约一秒钟的时间...

It performs many checks and color conversions you have no idea (it is literally tens of subcalls if not hundreds). That is why it is so slow it is not matter of Win10. this behavior is there all the time from windows start at least to my knowledge it is matter of GDI not VCL (it has nothing to do with Borland/Embarcadero VCL). So do not use Pixels[x][y] heavily. Even clearing 1024x1024 image this way can be a matter of around second on some machines...

VCL / GDI位图 ScanLine [y]

VCL/GDI Bitmap ScanLine[y]

这是 Borland / Embarcadero 特有的(在纯 GDI 上,您需要使用位锁定)。每个位图都有此属性/函数,该属性/函数返回指向任何 y 的位图原始数据的指针。它的速度和 Pixels [y] [x] 一样慢,但是如果您的位图没有更改其像素格式,也没有调整其大小,则指针仍然相同。

This is Borland/Embarcadero specific (on pure GDI you need to use bits locking instead). Each bitmap has this property/function which return pointer to raw data of the bitmap for any y. It is as slow as Pixels[y][x] but if your bitmap does not change its pixel format nor it is resized then the pointer is still the same.

这可用于直接像素访问,而不会影响性能。您只记得每个位图上的所有行都将调整大小/重新加载到自己的数组中。然后使用它。如果使用得当,通常比 Pixels [x] [y] 快达〜10000x 倍。

This can be used for direct pixel access without any performance hits. You just remember all lines at each bitmap resize/reload into own array like. And afterwards use just that. That is usually up to ~10000x times faster then Pixels[x][y] if used properly.

我通常将 ScanLine 指针复制到 C ++ 中自己的数组中,如下所示:

I usually copy ScanLine pointers to my own array in C++ like this:

// ok lests have some bitmap
Graphics::TBitmap *bmp=new Graphics::TBitmap;
bmp->Width=100;
bmp->Height=100;
// this is needed for direct pixel access after any LoadFromFile, Assign or resize 
bmp->HandleType=bmDIB;    // allows use of ScanLine
bmp->PixelFormat=pf32bit; // 32bit the same as int so we can use int* for pixels pointer

DWORD **pyx=new DWORD*[bmp->Height];
for (int y=0;y<bmp->Height;y++) pyx[y]=(DWORD*)bmp->ScanLine[y];

// now we can render pixels fast like this:
pyx[10][20]=0x0000FF00; // green dot at x=20, y=10
// and also read it back fast:
DWORD col=pyx[10][20];

因此将其移植到Delphi。请注意,在某些像素格式上,颜色是 RGB 而不是 BGR (反之亦然),因此在某些情况下,您需要反转 R,G,B 颜色的顺序(尤其是预定义的颜色)。

So port it to Delphi. Just beware that on some pixel formats the colors are RGB instead of BGR (or vice versa) so in some cases you need to reverse R,G,B order of colors (especially the predefined ones).

由于没有检查,因此请勿访问像素外的像素图

最后,不要忘了在不再需要时释放 pyx 数组(或

And lastly do not forget to release the pyx array when not needed anymore (or before new allocation)

这篇关于Delphi / C ++ Builder Windows 10 1709位图操作非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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