jpg图像打印有关问题
jpg图像打印问题
JPG格式图像是如何打印的?左边是图片列表,右边
界面上显示JPG图片,选中一项,如何只打印出这图片?而不打印其它的.
------解决方案--------------------
CDC *pDC;//屏幕DC
pDC = CDC::FromHandle(::GetDC(GetSafeHwnd()));//获取当前整个窗口DC
int BitPerPixel = pDC-> GetDeviceCaps(BITSPIXEL);//获得颜色模式
int Width = pDC-> GetDeviceCaps(HORZRES);
int Height = pDC-> GetDeviceCaps(VERTRES);
Width=Width/1.6;
Height=Height/1.68;
CDC memDC;//内存DC
memDC.CreateCompatibleDC(pDC);
CBitmap memBitmap, *oldmemBitmap;//建立和屏幕兼容的bitmap
memBitmap.CreateCompatibleBitmap(pDC, Width, Height);
oldmemBitmap = memDC.SelectObject(&memBitmap);//将memBitmap选入内存DC
memDC.BitBlt(0, 0, Width, Height, pDC, 0, 0, SRCCOPY);//复制屏幕图像到内存DC
//载入内存数据打印
CDC printDC;
CRect rect;
CPrintDialog printDlg(FALSE);
DOCINFO docInfo;
//自定义打印属性
if(printDlg.DoModal()==IDOK)
{
HDC hDC;
hDC=printDlg.GetPrinterDC();
if(!printDC.Attach(hDC))
return;
}
else
{
printDC.Detach();
return;
}
memset(&docInfo,0,sizeof(docInfo));
docInfo.cbSize=sizeof(DOCINFO);
docInfo.lpszDocName=L "Print Window ";
if(printDC.StartDoc(&docInfo) <=0)
{
#ifdef _DEBUG
AfxMessageBox(L "Start Doc Failed ");
#endif
printDC.Detach();
return;
}
printDC.StartPage();
printDC.SetMapMode(MM_TEXT);
GetClientRect(&rect);
//放大打印图片尺寸
printDC.StretchBlt(0,0,rect.Width()*11,rect.Height()*10,&memDC,0,0,rect.Width(),rect.Height(),SRCCOPY);
printDC.EndPage();
printDC.EndDoc();
printDC.Detach();
return;
找了好久才找到的截屏打印图片的代码 一定要给分的哦 呵呵
JPG格式图像是如何打印的?左边是图片列表,右边
界面上显示JPG图片,选中一项,如何只打印出这图片?而不打印其它的.
------解决方案--------------------
CDC *pDC;//屏幕DC
pDC = CDC::FromHandle(::GetDC(GetSafeHwnd()));//获取当前整个窗口DC
int BitPerPixel = pDC-> GetDeviceCaps(BITSPIXEL);//获得颜色模式
int Width = pDC-> GetDeviceCaps(HORZRES);
int Height = pDC-> GetDeviceCaps(VERTRES);
Width=Width/1.6;
Height=Height/1.68;
CDC memDC;//内存DC
memDC.CreateCompatibleDC(pDC);
CBitmap memBitmap, *oldmemBitmap;//建立和屏幕兼容的bitmap
memBitmap.CreateCompatibleBitmap(pDC, Width, Height);
oldmemBitmap = memDC.SelectObject(&memBitmap);//将memBitmap选入内存DC
memDC.BitBlt(0, 0, Width, Height, pDC, 0, 0, SRCCOPY);//复制屏幕图像到内存DC
//载入内存数据打印
CDC printDC;
CRect rect;
CPrintDialog printDlg(FALSE);
DOCINFO docInfo;
//自定义打印属性
if(printDlg.DoModal()==IDOK)
{
HDC hDC;
hDC=printDlg.GetPrinterDC();
if(!printDC.Attach(hDC))
return;
}
else
{
printDC.Detach();
return;
}
memset(&docInfo,0,sizeof(docInfo));
docInfo.cbSize=sizeof(DOCINFO);
docInfo.lpszDocName=L "Print Window ";
if(printDC.StartDoc(&docInfo) <=0)
{
#ifdef _DEBUG
AfxMessageBox(L "Start Doc Failed ");
#endif
printDC.Detach();
return;
}
printDC.StartPage();
printDC.SetMapMode(MM_TEXT);
GetClientRect(&rect);
//放大打印图片尺寸
printDC.StretchBlt(0,0,rect.Width()*11,rect.Height()*10,&memDC,0,0,rect.Width(),rect.Height(),SRCCOPY);
printDC.EndPage();
printDC.EndDoc();
printDC.Detach();
return;
找了好久才找到的截屏打印图片的代码 一定要给分的哦 呵呵