반응형
int nWidth, nHeight;
CClientDC dc(this); //this->pImgWnd
CDC MemDC;
MemDC.CreateCompatibleDC(&dc);
CRect rect;
GetClientRect(rect);
nWidth = rect.Width();
nHeight = rect.Height();
CBitmap BMP;
BMP.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height());
CBitmap* pOldBitmap = MemDC.SelectObject(&BMP);
MemDC.BitBlt(0, 0, nWidth, nHeight, &dc, 0, 0, SRCCOPY);
/*
SECJpeg* jpg = new SECJpeg();
jpg->CreateFromBitmap(&MemDC,&BMP);
jpg->SaveImage("Test.jpg");
*/
HANDLE hDib;
LPSTR pDib;
LPBITMAPINFO lpBitInfo;
HANDLE hlpBitInfo;
//CBitmap BMP;
//BMP.LoadBitmap(IDB_BITMAP1);
hDib=GlobalAlloc(GHND,nWidth*nHeight*3);
pDib=(LPSTR)GlobalLock(hDib);
hlpBitInfo=GlobalAlloc(GHND,sizeof(BITMAPINFOHEADER)+ sizeof(BITMAPINFO));
lpBitInfo=(LPBITMAPINFO)GlobalLock(hlpBitInfo);
//BITMAPINFO
lpBitInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
lpBitInfo->bmiHeader.biWidth = nWidth;
lpBitInfo->bmiHeader.biHeight = nHeight;
lpBitInfo->bmiHeader.biPlanes = 1;
lpBitInfo->bmiHeader.biBitCount = 24;
lpBitInfo->bmiHeader.biCompression = BI_RGB;
lpBitInfo->bmiHeader.biSizeImage = nWidth * nHeight * 3;
lpBitInfo->bmiHeader.biXPelsPerMeter = 0;
lpBitInfo->bmiHeader.biYPelsPerMeter = 0;
lpBitInfo->bmiHeader.biClrUsed = 0;
lpBitInfo->bmiHeader.biClrImportant = 0;
////BITMAPINFO
HDC hdc=::GetDC(this->m_hWnd);
GetDIBits(hdc, (HBITMAP)BMP, 0, nHeight, pDib, lpBitInfo, DIB_RGB_COLORS);
::ReleaseDC(this->m_hWnd, hdc);
static DOCINFO docinfo= {sizeof(DOCINFO), _T("IMAGE"), NULL};
CPrintDialog dlg(FALSE);
if(dlg.DoModal()== IDCANCEL)
return;
HDC hpdc= dlg.GetPrinterDC();
int cx, cy ;
cy=GetDeviceCaps(hpdc,VERTRES);
cx=GetDeviceCaps(hpdc,HORZRES);
if(StartDoc(hpdc,&docinfo))
{
if(StartPage(hpdc))
{
StretchDIBits(hpdc,
0, 0, cx, cy, 0, 0, nWidth, nHeight, pDib, lpBitInfo, DIB_RGB_COLORS,SRCCOPY);
EndPage(hpdc);
}
EndDoc(hpdc);
}
::RestoreDC(hpdc, -1);
반응형
'C & C++ > MFC Media' 카테고리의 다른 글
BMP, GIF, JPG 수정하기 (0) | 2012.06.20 |
---|---|
DLL 에 있는 비트맵(Bitmap) 리소스를 실행 파일로 가져오는 방법 3가지 (0) | 2011.12.14 |
CListCtrl 에 이미지(tga, png, jpg, tif, bmp) 컨트롤 하기 (0) | 2011.04.28 |
배경 이미지 연속적으로 돌리기 (0) | 2011.04.28 |
화면 갱신 OnPaint(), OnDraw(), Invalidate() (0) | 2011.04.27 |
댓글