Solved

StretchBlt() problem - downsized image looks ugly.

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

840 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