Solved

Getting scaled images to look better than just a StretchBlt

Posted on 1998-06-02
4
494 Views
Last Modified: 2013-12-03
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
0
Comment
Question by:circuit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1406683
1. You must select the palette into all the DCs you are operating on and realize it.

2. Try SetStretchBltMode.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1406684
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.)
0
 

Author Comment

by:circuit
ID: 1406685
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++
0
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1406686
You can use GetDeviceCaps function (RC_PALETTE) to determine if the DC supports a palette.

Thank you.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question