Solved

StretchBlt() problem - downsized image looks ugly.

Posted on 2004-08-19
4
869 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

863 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

25 Experts available now in Live!

Get 1:1 Help Now