Jump to content
  • Advertisement
Sign in to follow this  
GetWindowRect

Get the Height and Width of a bitmap.

This topic is 4836 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to load a bitmap from either file, or resource and stretch/shrink it to the size of a window to display it as a background image. The problem is I think I need to use the StretchBlt API which requires the image width and image height to know how much to stretch or shrink the image. I was thinking of using the GetDeviceCaps API with LOGPIXELSX/Y, or HORZ/VERTRES or HORZ/VERTSIZE. The problem is they return the screens information, not the bitmaps. I am wondering if SelectObject(hdc, hbitmap) when hdc is created as CreateCompatibleDC(hdcOriginal) and hdcOriginal is created as GetDC(wndHandle). Is there a way to only select the bitmap into a DC and get the size or any other way I do not know of. I cannot find anything under google except for examples with MFC. Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement

//Assuming you have a HDC called HDCSource

int width = 0, height = 0;
HBITMAP hinfoBitmap = (HBITMAP)GetCurrentObject(HDCSource, OBJ_BITMAP);
if(hinfoBitmap)
{
BITMAP infoBitmap;
GetObject(hinfoBitmap, sizeof(infoBitmap), &infoBitmap);
width = infoBitmap.bmWidth;
height = infoBitmap.bmHeight;
}

Share this post


Link to post
Share on other sites
Thank you very much for your help, it seems to work well now. However, could you tell me if StretchBlt will make images look horrible if they are shrunk by, lets say, 25%? The images I have loaded look horrible when displayed on my window.

Share this post


Link to post
Share on other sites
StretchBlt will make images look horrible, period. It doesn't perform resampling of any sort, so pixels are directly copied or deleted according to a really simple algorithm, and the end result is faster but doesn't look so nice.

Share this post


Link to post
Share on other sites
If StretchBlt() is not a good method, could you tell me if there are any out there or would I have to learn how to do it myself? I am guessing PutPixel() or something is what I would have to use to do it myself, but I am very new when it comes to messing with images.

Share this post


Link to post
Share on other sites
If you are only interested in targeting Win2k or later, you can call SetStretchBltMode and set the mode to HALFTONE. That will at least filter the pixels when a dimension is scaled down. If you want anything better than that, or you also want to target Win9x, then you will need another solution.

Share this post


Link to post
Share on other sites
I changed the second and third to last parameters in the LoadImage function to the size I wanted the image. It seems to work fine, and the image is clear and looks decent. I am not sure if this is the best method of dealing with it, but for now it seems to work well.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!