Solved

Getting scaled images to look better than just a StretchBlt

Posted on 1998-06-02
4
481 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to have excel show file name on the title bar 4 63
Windows Drag & Drop Location 2 112
Explain Unit of Work pattern 2 76
windbg taking it's time 32 100
This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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