?
Solved

StretchBlt() problem - downsized image looks ugly.

Posted on 2004-08-19
4
Medium Priority
?
914 Views
Last Modified: 2012-08-14
I'm loading a full size, 24bit color bitmap from a file, and attempting to display it in a reduced size (thumbnail) - when I click it, it loads full-size into a direct draw surface.  Functionally, everything is working, my problem is that the thumbnails are corrupt. It's hard to explain w/o seeing but I'll try. The picture itself is pretty much correct, size, placement and orientation are all correct. Large areas of the image look as they should pretty much, but the smaller version looks, well, dithered is probably the closest word. One image is a womans face. When I show it full size using StretchBlt() it looks perfect, exactly as it does when I load it in Photoshop. (I could probably use Blt() for the fullsize, but I'm only pointing this out since my thumbnail is created with the same code)

it's like, instead of her having rosy cheeks nicely "made up", it's like her cheek is chunks of tan, chunks of a ligher tan, chunks of pink.. Actually, now that I type this it's ringing a bell... I just opened the image in Photoshop and remapped it to 8 colors and shunk it, and except for the pink streaks, it looks just like this thumbnail version I'm seeing in my app.

Here is the code I use to pull in the file and display it, minus error checking for clarity.

---------------------
HDC                     hdcImage;
HDC                     hdc;
BITMAP                  bm;
DDSURFACEDESC           ddsd;
HRESULT                 hr;
HBITMAP hbm = (HBITMAP) ::LoadImage( NULL, a_lpszImageName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);

// Select bitmap into a memoryDC so we can use it.
hdcImage = CreateCompatibleDC(NULL);

SelectObject(hdcImage, hbm);

// Get size of the bitmap
GetObject(hbm, sizeof(bm), &bm);

int iWidth, iHeight;
iWidth = bm.bmWidth;
iHeight = bm.bmHeight;

// Get size of surface.
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
m_pSurface->GetSurfaceDesc(&ddsd);

if ((hr = m_pSurface->GetDC(&hdc)) == DD_OK)
{
StretchBlt(hdc, iXSurfacePos, iYSurfacePos, m_iElementSurfaceWidth, m_iElementSurfaceHeight, hdcImage, 0, 0, iWidth, iHeight, SRCCOPY);
m_pSurface->ReleaseDC(hdc);
}
DeleteDC(hdcImage);

// --------------------------------
// Get size of window's client area
// --------------------------------
CRect ClientRect;
this->GetClientRect(ClientRect);
// ----------------
// repaint the view
// ----------------

RedrawWindow(ClientRect, NULL, RDW_INVALIDATE);
---------------------

the coordinate/height/width values I'm using I've calculated prior to this code, and that is all working.

What's going wrong here? It's likely something simple.

thanks
-Paul
0
Comment
Question by:PMH4514
[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
4 Comments
 
LVL 3

Expert Comment

by:Indrawati
ID: 11848175
I have the same problem before, and I guess it's because StretchBlt''s resizing functiion is not that good. I tried resizing the image manually to fit the window and then display the image using BitBlt instead of StretchBlt, and it works OK.
0
 

Author Comment

by:PMH4514
ID: 11851818
actually I just figured it out. if I preceed the StretchBlt() call with this: SetStretchBltMode(hdc, HALFTONE);  the downsized image looks perfect.  I guess I'll have to have the moderator close out this question.
0
 
LVL 2

Accepted Solution

by:
Lunchy earned 0 total points
ID: 11885930
Closed, 50 points refunded.
Lunchy
Friendly Neighbourhood Community Support Admin
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

719 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