Solved

StretchBlt() problem - downsized image looks ugly.

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

785 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