Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting scaled images to look better than just a StretchBlt

Posted on 1998-06-02
4
Medium Priority
?
533 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 400 total points
ID: 1406686
You can use GetDeviceCaps function (RC_PALETTE) to determine if the DC supports a palette.

Thank you.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
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 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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

604 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