|
-
July 5th, 2012, 02:35 PM
#1
How to get an file-loaded bitmap to fit a static image container using StretchBlt ?
The code below will load a bitmap from a disk file. How can I get the loaded bitmap, regardless of it's original size, to fit into an existing interface static image container?
Code:
void CMyDlg::OnFileOpen()
{
CString m_csPathname, m_csFilename;
const wchar_t fileDialogFilter[] =
_T("Bitmap Files(*.bmp)|*.bmp||");
const wchar_t fileDialogExt[] = _T("bmp");
CFileDialog fileDialog(TRUE,
fileDialogExt, NULL,
OFN_FILEMUSTEXIST, fileDialogFilter);
if (fileDialog.DoModal() == IDOK)
{
CWaitCursor wait;
m_csPathname = fileDialog.GetPathName();
m_csFilename = fileDialog.GetFileName();
SetWindowText(m_csFilename);
}
CWaitCursor wait;
// Load the Image File
HBITMAP hBmp = (HBITMAP)::LoadImage(NULL, m_csPathname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
// The StretchBlt function copies a bitmap from a source rectangle into a destination rectangle, stretching or
// compressing the bitmap to fit the dimensions of the destination rectangle, if necessary. The system stretches or
// compresses the bitmap according to the stretching mode currently set in the destination device context.
//
// BOOL StretchBlt(
// __in HDC hdcDest, // A handle to the destination device context.
// __in int nXOriginDest, // The x-coordinate, in logical units, of the upper-left corner of the destination rectangle.
// __in int nYOriginDest, // The y-coordinate, in logical units, of the upper-left corner of the destination rectangle.
// __in int nWidthDest, // The width, in logical units, of the destination rectangle.
// __in int nHeightDest, // The height, in logical units, of the destination rectangle.
// __in HDC hdcSrc, // A handle to the source device context.
// __in int nXOriginSrc, // The x-coordinate, in logical units, of the upper-left corner of the source rectangle.
// __in int nYOriginSrc, // The y-coordinate, in logical units, of the upper-left corner of the source rectangle.
// __in int nWidthSrc, // The width, in logical units, of the source rectangle.
// __in int nHeightSrc, // The height, in logical units, of the source rectangle.
// __in DWORD dwRop // The raster operation to be performed. Raster operation codes define how the system combines colors in output operations that involve a brush, a source bitmap, and a destination bitmap.
// );
m_cImage.SetBitmap(hBmp);
m_csEdit1.Empty();
m_csEdit2.Empty();
m_csEdit3.Empty();
UpdateData(FALSE);
}// OnFileOpen()
It is my understanding that the StretchBlt(...) function pertains to the destination device context. I am unclear as to how to determine the rectangle of the bitmap that has been loaded and what the dwRop is supposed to be. I have not found a suitable example.
mpliam
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|