Link to home
Start Free TrialLog in
Avatar of circuit
circuit

asked on

Getting scaled images to look better than just a StretchBlt

I have been using StretchBlt to scale images in my Windows app, but they look really bad.  They seem to be suffering both from aliasing artifacts and color palette problems (even though I'm running in 16-bit mode).

Can you suggest a scaling algorithm which will scale and filter an image?
I would like a function that has a prototype like:

HBITMAP FilteredScale (HBITMAP hbm, HDC hdc);

Here's my current algorithm:
HBITMAP ImageManager::GetBitmap (CString filename, int width, int height, CDC *dc)
{
      BOOL success;
      HBITMAP bitmap = GetBitmap (filename, dc);
      PetzAssert (bitmap);
      HDC hdc = dc->GetSafeHdc();
      HDC memDC = CreateCompatibleDC (hdc);
      PetzAssert (memDC);

      HBITMAP newBitmap = CreateCompatibleBitmap (hdc, width, height);
      SelectObject (memDC, newBitmap);

      success = StretchBitmap (memDC, 0,0, width, height, bitmap, SRCCOPY);
      SelectObject (memDC, bitmap);

      DeleteObject (bitmap);
      DeleteDC(memDC);
      return newBitmap;
}

Thanks for your help,
Brett
Avatar of chensu
chensu
Flag of Canada image

1. You must select the palette into all the DCs you are operating on and realize it.

2. Try SetStretchBltMode.
Avatar of nietod
nietod

It seems to me that there is no way to make a stetched bitmap look good.  If you know you are going to be stretching an image (and if possible under your circumstances) try using a meta file.  They can be stretched (I believe--I don't use them.)
Avatar of circuit

ASKER

chensu, thank you very much.  I called SetStretchBltMode (COLORONCOLOR) and that took care of the problems I was having.  I will also get the current palette, set and realize it in my memory dc, but I think this is only for 256 color mode.

Thanks again,
bre++
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial