gdi + Graphics :: DrawImage真的很慢~~ [英] gdi+ Graphics::DrawImage really slow~~

查看:678
本文介绍了gdi + Graphics :: DrawImage真的很慢~~的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GDI +图形在屏幕上绘制4000 * 3000的图像,但这确实很慢.大约需要300毫秒.我希望它只占用不到10毫秒的时间.

I am using a GDI+ Graphic to draw a 4000*3000 image to screen, but it is really slow. It takes about 300ms. I wish it just occupy less than 10ms.

Bitmap *bitmap = Bitmap::FromFile("XXXX",...);

//-------------------------------------------- //这部分大约需要300毫秒,太可怕了!

//-------------------------------------------- // this part takes about 300ms, terrible!

int width = bitmap->GetWidth();
int height = bitmap->GetHeight();
DrawImage(bitmap,0,0,width,height);

//------------------------------------------

//------------------------------------------

我不能使用CachedBitmap,因为我想稍后再编辑位图.

I cannot use CachedBitmap, because I want to edit the bitmap later.

我该如何改善?还是有什么问题吗?

How can I improve it? Or is any thing wrong?

此本地GDI功能还将图像绘制到屏幕中,仅需1毫秒:

This native GDI function also draws the image into the screen, and it just take 1 ms:

SetStretchBltMode(hDC, COLORONCOLOR);   
StretchDIBits(hDC, rcDest.left, rcDest.top, 
        rcDest.right-rcDest.left, rcDest.bottom-rcDest.top, 
        0, 0, width, height,
        BYTE* dib, dibinfo, DIB_RGB_COLORS, SRCCOPY);

//--------------------------------------------- -----------------

//--------------------------------------------------------------

如果我想使用StretchDIBits,则需要传递BITMAPINFO,但是如何从Gdi +位图对象获取BITMAPINFO?我通过FreeImage lib进行了实验,我使用FreeImageplus对象调用StretchDIBits,它绘制得非常快.但是现在我需要绘制位图,并在位图的位数组上编写一些算法,如果有位图对象,如何获得BITMAPINFO?真的很烦-___________- |

If I want to use StretchDIBits, I need to pass BITMAPINFO, But how can I get BITMAPINFO from a Gdi+ Bitmap Object? I did the experiment by FreeImage lib, I call StretchDIBits using FreeImageplus object, it draw really fast. But now I need to draw Bitmap, and write some algorithm on Bitmap's bits array, how can I get BITMAPINFO if I have an Bitmap object? It's really annoying -___________-|

推荐答案

您的屏幕分辨率为4000 x 3000?哇!

You have a screen of 4000 x 3000 resolution? Wow!

如果没有,您应该只绘制图像的可见部分,这样会更快...

If not, you should draw only the visible part of the image, it would be much faster...

[第一次评论后编辑]我的话确实有些愚蠢,我想DrawImage会遮盖/跳过不需要的像素.

My remark is indeed a bit stupid, I suppose DrawImage will mask/skip unneeded pixels.

编辑后(显示StretchDIBits),我想速度差异的可能来源可能是 StretchDIBits 是硬件加速的("如果驱动程序不能支持JPEG或PNG文件图像"是提示...),而DrawImage可能是(我没有证据!)用C编码,依赖于CPU的能力而不是GPU的能力.

After your edit (showing StretchDIBits), I guess a possible source of speed difference might come from the fact that StretchDIBits is hardware accelerated ("If the driver cannot support the JPEG or PNG file image" is a hint...) while DrawImage might be (I have no proof for that!) coded in C, relying on CPU power instead of GPU's one...

如果我没记错的话,DIB图像速度很快(尽管是与设备无关的").请参见高速Win32动画:"使用CreateDIBSection进行高速动画".好的,它适用于旧版Windows(1996年!)中的DIB与GDI.但是我认为这仍然是正确的.

If I recall correctly, DIB images are fast (despite being "device independent"). See High Speed Win32 Animation: "use CreateDIBSection to do high speed animation". OK, it applies to DIB vs. GDI, in old Windows version (1996!) but I think it is still true.

也许位图:: GetHBITMAP 函数可能会帮助您使用StretchDIBits(未经测试...).

Maybe Bitmap::GetHBITMAP function might help you to use StretchDIBits (not tested...).

这篇关于gdi + Graphics :: DrawImage真的很慢~~的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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