views:

675

answers:

4

So I've read that StretchBlt can mirror images horizontally and/or vertically by negating the nWidthSrc/Dest and nHeightSrc/Dest parameters. I'd like this functionality without the performance overhead of a StretchBlt. I tried the same technique with BitBlt but it didn't work.

Is there any way to mirror an image with something as simple as BitBlt, without the overkill of a StretchBlt? Or will StretchBlt not affect performance if the source and destination sizes are the same?

A: 

To mirror an image you just need to loop through the pixels in reverse order. Such as if you want to mirror horizontally you just need to do the following:

  1. expand image canvas to double the size
  2. start at the bottom of the image and work you way up writing the pixels in to the mirrored area from the top down.
  3. do step 3 from left to right.

I don't know what language you are using, but most of them allow you to manipulates the pixels or bits on an individual basis using GDI.

Nick Berardi
+1  A: 

All Win32 functions are probably going to be extremely optimized.

What makes you think StretchBlt will be a big performance hit?

Have you profiled your application using StretchBlt?

You could reverse all of the bitmap data yourself and see if you can do better that StretchBlt.

Here's a link that might help you out:

http://www.codeguru.com/cpp/g-m/bitmap/specialeffects/article.php/c1739

A: 

No way you are going to be more efficient that StretchBlt, unless you know some extra information about the image (e.g, there is a border so you don't have to flip certain pixels.

Nick
+2  A: 

BitBlt will only perform mathmatic operations (or, xor, etc) on the individual pixels in question, it will not resize the image in any way. That is exactly what StretchBlt is for, and StretchBlt (compared to any other graphics resizing operation) is insanely fast as in most cases it can use the graphics card to accelerate its performance.

Kris Erickson