Solved

Getting scaled images to look better than just a StretchBlt

Posted on 1998-06-02
4
446 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
  • 2
4 Comments
 
LVL 23

Expert Comment

by:chensu
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
You can use GetDeviceCaps function (RC_PALETTE) to determine if the DC supports a palette.

Thank you.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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 tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now