From: Joe on
How do I stretch or shrink a bitmap (or other image) to fit into the
rectangle defined by a CStatic Picture Box "m_Picture"?

The following code will load the image from a file specified by "strBmp,"
but it will not stretch or shrink it to fill the Picture Box control.

Would someone *please* show me what to edit and how to edit it so that the
code below will also resize the image to the "m_Picture" control's size?

void ChangePicture(CString strBmp)
{
HBITMAP h_bmpNew, h_bmpOld;
h_bmpNew = SHLoadDIBitmap(strBmp);
if (h_bmpNew != NULL)
{
CRect r1;
m_Picture.GetWindowRect(&r1);
ScreenToClient(&r1);
h_bmpOld = m_Picture.SetBitmap(h_bmpNew);
if (h_bmpOld != NULL) {
::DeleteObject(h_bmpOld);
}
InvalidateRect(&r1);
}
}
From: " ctacke/>" on
Look at the StretchBlt API

-Chris



"Joe" <Joe(a)discussions.microsoft.com> wrote in message
news:FD9F7063-1344-4C1D-BCA7-A45A3B9DD1C1(a)microsoft.com...
> How do I stretch or shrink a bitmap (or other image) to fit into the
> rectangle defined by a CStatic Picture Box "m_Picture"?
>
> The following code will load the image from a file specified by "strBmp,"
> but it will not stretch or shrink it to fill the Picture Box control.
>
> Would someone *please* show me what to edit and how to edit it so that the
> code below will also resize the image to the "m_Picture" control's size?
>
> void ChangePicture(CString strBmp)
> {
> HBITMAP h_bmpNew, h_bmpOld;
> h_bmpNew = SHLoadDIBitmap(strBmp);
> if (h_bmpNew != NULL)
> {
> CRect r1;
> m_Picture.GetWindowRect(&r1);
> ScreenToClient(&r1);
> h_bmpOld = m_Picture.SetBitmap(h_bmpNew);
> if (h_bmpOld != NULL) {
> ::DeleteObject(h_bmpOld);
> }
> InvalidateRect(&r1);
> }
> }


From: Joe on
I have, but it takes two HDCs (one for source and one for destination) that I
don't know how to create. My destination is a CStatic Picture Box control
called m_Picture, and my source is a CString path to a file called strBmp.

Further, StretchBlt requires the rectangle dimentions (left, top, Width, and
Height). How do I get those dimentions from a CString path?

How would I create the parameters needed to call StretchBlt? Then, do I
call StretchBlt before or after my code calls SetBitmap?

"<ctacke/>" wrote:

> Look at the StretchBlt API
>
> -Chris

From: " ctacke/>" on
I think you need to become one with the Win32 API before working with
wrappers like MFC so you can actually understand what's going on under the
hood.

GetObject on your HBITMAP will return a BITMAP, which will tell you its
size.
CreateCompatibleDC would generate a DC compatible with your CStatic
SelectObject can put a bitmap into a DC
CreateCompatibleBitmap would generate a buffer into which you could
StretchBlt

There are probably MFC wrappers that handle these as well (like CBitmap and
CDC) but again, if you understand how to do it in Win32, you shouldn't be
doing it with a wrapper class.

--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--




"Joe" <Joe(a)discussions.microsoft.com> wrote in message
news:594BA595-214A-4A9B-B9DA-328C54E46321(a)microsoft.com...
>I have, but it takes two HDCs (one for source and one for destination) that
>I
> don't know how to create. My destination is a CStatic Picture Box control
> called m_Picture, and my source is a CString path to a file called strBmp.
>
> Further, StretchBlt requires the rectangle dimentions (left, top, Width,
> and
> Height). How do I get those dimentions from a CString path?
>
> How would I create the parameters needed to call StretchBlt? Then, do I
> call StretchBlt before or after my code calls SetBitmap?
>
> "<ctacke/>" wrote:
>
>> Look at the StretchBlt API
>>
>> -Chris
>


From: Joe on
At this point, I don't know how to tell what is MFC and what is Win32 API.
Currently, I have books on MFC and a book on Win32 API being shipped here.

For GetObject, I used like so:
BITMAP bitmap;
HBITMAP hbitmap = SHLoadDIBitmap(strBmp);
if (hbitmap)
{
CRect r1, r2;
::GetObject(hbitmap, sizeof(BITMAP), &bitmap);
r2.top = r2.left = 0;
r2.bottom = bitmap.bmHeight;
r2.right = bitmap.bmWidth;
m_Picture.GetWindowRect(&r1); // m_Picture is CStatic Pic Box control
ScreenToClient(&r1);
// now what?
}

CreateCompatibleDC(HDC) requires an HDC structure. How do I get that from
the CStatic m_Picture?

"<ctacke/>" wrote:

> I think you need to become one with the Win32 API before working with
> wrappers like MFC so you can actually understand what's going on under the
> hood.
>
> GetObject on your HBITMAP will return a BITMAP, which will tell you its
> size.
> CreateCompatibleDC would generate a DC compatible with your CStatic
> SelectObject can put a bitmap into a DC
> CreateCompatibleBitmap would generate a buffer into which you could
> StretchBlt
>
> There are probably MFC wrappers that handle these as well (like CBitmap and
> CDC) but again, if you understand how to do it in Win32, you shouldn't be
> doing it with a wrapper class.
>
> --
> Chris Tacke
> OpenNETCF Consulting
> Managed Code in the Embedded World
> www.opennetcf.com
> --