Solved

StretchBlt() problem - downsized image looks ugly.

Posted on 2004-08-19
4
860 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
Comment Utility
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
Comment Utility
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
Comment Utility
Closed, 50 points refunded.
Lunchy
Friendly Neighbourhood Community Support Admin
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 learn how to clear a vector as well as how to detect empty vectors in C++.

772 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

10 Experts available now in Live!

Get 1:1 Help Now