3

I want to resize image size. So currently i do this:

SetStretchBltMode(hCompatibleDC, HALFTONE); 
StretchBlt(hCompatibleDC, 0, 0, Des_w, Des_h, mhDesktopDC, 0, 0, src_w, src_h, SRCCOPY);

But this is very slow.

From my tests, BitBlt is x75 faster than StretchBlt. I need BitBlt/StretchBlt to get the bits array from the CompatibleDC.

I would like to try to use BitBlt instead of StretchBlt (for getting the RGB 24bits array) and to send to my own function that will do the resize.

Now to be serious, i do not have the knowledge to write function that will do that faster than StretchBlt and in the same quality as HALFTONE.

Maybe even ASM is needed - which i do not know. I am writing in C++ (visual studio) So i would like to know if you can help in this. Thanks!

  • 2
    What do you mean by "slow"? What are you doing overall (how many `StretchBlt` are you doing, what size is the input and output, etc?). As a rule, StretchBlt will be a little bit slower than BitBlt - how much slower depends on what hardware you are using. I doubt someone that hasn't got MUCH experience in writing bitblt style functions will achieve better results than Microsoft's code. And assuming there is support in hardware, the driver should do this fairly rapidly - at least a few hundred to a few thousand 1024 x 800 images per second, as long as the original isn't much larger. – Mats Petersson May 03 '14 at 22:34
  • 1
    Hi Mats. SRC: 1440X900 Dest: 1200X700 This: BitBlt(hCompatibleDC, 0, 0, 1200, 700, hDesktopDC, 0, 0, SRCCOPY); on my computer runs 1900 times per second. This: StretchBlt(hCompatibleDC, 0, 0, 1200, 700, hDesktopDC, 0, 0, 1440, 900, SRCCOPY); With HALFTONE, runs only 26 times per second. I need at least 80 times per second. – user3600152 May 03 '14 at 23:02
  • Downsampling using a filter is notoriously slow -- it says so much on the MSDN page for StretchBlt. "Doing it manually", with a routine your wrote yourself, may be yet even slower; you have to do pretty much the same work (iterating over a **million** pixels) but in addition set up memory, copy the original bitmap in it, copy the *new* pixels into another bitmap, etc. You can be sure Windows' own APIs already use all available shortcuts. If speed is more important than quality, don't use HALFTONE. And the other way around. – Jongware May 04 '14 at 00:07
  • Without HALFTONE the quality is very low. So what should i do? live with that that i can only have 26 images per second? – user3600152 May 04 '14 at 09:09
  • Yes -- Or live with a lower quality. But all is not lost, yet. For example, you don't tell where this large image comes from. If it is a static image, all you have to do is resize it *once*. – Jongware May 04 '14 at 12:50
  • Hi. It is screenshot i take - so no it is not static ... – user3600152 May 04 '14 at 16:07
  • Anything that can be done? – user3600152 May 04 '14 at 18:20
  • You could look into using D3D or OpenGL. But if your 2d rendering is not fast, I am thinking 3d may not help you. That being said, the functions Windows is trying to use may not be available (not advertised) on your video board. Finally, if you are writing a desktop app. that should run on any computer (opposed to embedded), there's no good solution. – Alexis Wilke May 07 '14 at 02:27

0 Answers0