OpenCV 打印图片对话框功能
2013-07-21 22:30
190 查看
这只是一个打印VS上的一个对话框的功能,需要在VS上安装OpenCV
CRect m_rect,framerect;
//获取对话框大小
GetWindowRect(m_rect);
//获取图片控件大小
m_Frame.GetWindowRect(framerect);
int x,y;
x=framerect.left-m_rect.left;
CDC* pImageDC=GetDC();
int formx,formy;
formx=pImageDC->GetDeviceCaps(LOGPIXELSX);
formy=pImageDC->GetDeviceCaps(LOGPIXELSY);
ReleaseDC(pImageDC);
DWORD dwflags=PD_PAGENUMS|PD_HIDEPRINTTOFILE|PD_SELECTION; //设置打印对话框风格
CPrintDialog m_printdlg(FALSE,dwflags,NULL); //创建打印对话框
if(m_printdlg.DoModal()==IDOK)
{
CDC pdc;
pdc.Attach(m_printdlg.GetPrinterDC());
//获取打印机与屏幕的分辨率
int printerx,printery;
printerx=pdc.GetDeviceCaps(LOGPIXELSX);
printery=pdc.GetDeviceCaps(LOGPIXELSY);
double ratex,ratey;
ratex=(double)printerx/formx;
ratey=(double)printery/formy;
CClientDC dc(this);
CBitmap bmp;
bmp.CreateCompatibleBitmap(&dc,framerect.Width()+x,framerect.Height()+x);
CDC imagedc;
imagedc.CreateCompatibleDC(&dc);
imagedc.SelectObject(&bmp);
imagedc.BitBlt(0,0,framerect.Width()+x,framerect.Height()+x,&dc,0,0,SRCCOPY);
BITMAP bmap;
bmp.GetBitmap(&bmap);
int panelsize=0;
//非真彩色位图
if(bmap.bmBitsPixel<16)
{
panelsize=pow(2,bmap.bmBitsPixel*sizeof(RGBQUAD));
}
BITMAPINFO* bInfo=(BITMAPINFO*)LocalAlloc(LPTR,sizeof(BITMAPINFO)+panelsize);
bInfo->bmiHeader.biClrImportant=0;
bInfo->bmiHeader.biBitCount=bmap.bmBitsPixel;
bInfo->bmiHeader.biCompression=0;
bInfo->bmiHeader.biHeight=bmap.bmHeight;
bInfo->bmiHeader.biPlanes=bmap.bmPlanes;
bInfo->bmiHeader.biSize=sizeof(BITMAPINFO);
bInfo->bmiHeader.biSizeImage=bmap.bmWidthBytes*bmap.bmHeight;
bInfo->bmiHeader.biWidth=bmap.bmWidth;
bInfo->bmiHeader.biXPelsPerMeter=0;
bInfo->bmiHeader.biYPelsPerMeter=0;
char *pData=new char[bmap.bmWidthBytes*bmap.bmHeight];
::GetDIBits(imagedc.m_hDC,bmp,0,bmap.bmHeight,pData,bInfo,DIB_RGB_COLORS);
//打印图像
pdc.StartDoc("print");
::StretchDIBits(pdc.m_hDC,50,50,(int)((framerect.Width()*ratex)+x),
(int)((framerect.Height()+x)*ratey),0,0,framerect.Width()+x,
framerect.Height()+x,pData,bInfo,DIB_RGB_COLORS,SRCCOPY);
pdc.EndDoc();
LocalFree(bInfo);
delete[] pData;
bmp.DeleteObject();
}
CRect m_rect,framerect;
//获取对话框大小
GetWindowRect(m_rect);
//获取图片控件大小
m_Frame.GetWindowRect(framerect);
int x,y;
x=framerect.left-m_rect.left;
CDC* pImageDC=GetDC();
int formx,formy;
formx=pImageDC->GetDeviceCaps(LOGPIXELSX);
formy=pImageDC->GetDeviceCaps(LOGPIXELSY);
ReleaseDC(pImageDC);
DWORD dwflags=PD_PAGENUMS|PD_HIDEPRINTTOFILE|PD_SELECTION; //设置打印对话框风格
CPrintDialog m_printdlg(FALSE,dwflags,NULL); //创建打印对话框
if(m_printdlg.DoModal()==IDOK)
{
CDC pdc;
pdc.Attach(m_printdlg.GetPrinterDC());
//获取打印机与屏幕的分辨率
int printerx,printery;
printerx=pdc.GetDeviceCaps(LOGPIXELSX);
printery=pdc.GetDeviceCaps(LOGPIXELSY);
double ratex,ratey;
ratex=(double)printerx/formx;
ratey=(double)printery/formy;
CClientDC dc(this);
CBitmap bmp;
bmp.CreateCompatibleBitmap(&dc,framerect.Width()+x,framerect.Height()+x);
CDC imagedc;
imagedc.CreateCompatibleDC(&dc);
imagedc.SelectObject(&bmp);
imagedc.BitBlt(0,0,framerect.Width()+x,framerect.Height()+x,&dc,0,0,SRCCOPY);
BITMAP bmap;
bmp.GetBitmap(&bmap);
int panelsize=0;
//非真彩色位图
if(bmap.bmBitsPixel<16)
{
panelsize=pow(2,bmap.bmBitsPixel*sizeof(RGBQUAD));
}
BITMAPINFO* bInfo=(BITMAPINFO*)LocalAlloc(LPTR,sizeof(BITMAPINFO)+panelsize);
bInfo->bmiHeader.biClrImportant=0;
bInfo->bmiHeader.biBitCount=bmap.bmBitsPixel;
bInfo->bmiHeader.biCompression=0;
bInfo->bmiHeader.biHeight=bmap.bmHeight;
bInfo->bmiHeader.biPlanes=bmap.bmPlanes;
bInfo->bmiHeader.biSize=sizeof(BITMAPINFO);
bInfo->bmiHeader.biSizeImage=bmap.bmWidthBytes*bmap.bmHeight;
bInfo->bmiHeader.biWidth=bmap.bmWidth;
bInfo->bmiHeader.biXPelsPerMeter=0;
bInfo->bmiHeader.biYPelsPerMeter=0;
char *pData=new char[bmap.bmWidthBytes*bmap.bmHeight];
::GetDIBits(imagedc.m_hDC,bmp,0,bmap.bmHeight,pData,bInfo,DIB_RGB_COLORS);
//打印图像
pdc.StartDoc("print");
::StretchDIBits(pdc.m_hDC,50,50,(int)((framerect.Width()*ratex)+x),
(int)((framerect.Height()+x)*ratey),0,0,framerect.Width()+x,
framerect.Height()+x,pData,bInfo,DIB_RGB_COLORS,SRCCOPY);
pdc.EndDoc();
LocalFree(bInfo);
delete[] pData;
bmp.DeleteObject();
}
相关文章推荐
- PHP实现将几张照片拼接到一起的合成图片功能【便于整体打印输出】
- 想在对话框中使用CView的打印/预览功能“ERROR: Cannot find dialog template with IDD 0x7803.”
- WinXP使用图片和传真查看器功能在一张纸上打印多幅图片
- 实现SWT打印表格与图片功能(ZT)
- 利用Qt的标准文件对话框及OpenCV创建窗口并显示图片
- VC++ 简单的打印功能(对话框模式下)
- java绘制图片并打印功能
- opencv实现图片与视频中人脸检测功能
- 利用OPenCV在MFC对话框上显示图片
- MFC的对话框中用OPENCV添加图片
- 报表软件finereport7.0新增图片打印功能
- 在VC对话框中实现打印功能
- Android系统默认对话框添加图片功能
- python+opencv实现简单的图片搜索功能
- MFC打印对话框及控件功能
- MFC中在对话框中显示图片(从此摆脱opencv升级后无CvvImage的烦恼)
- opencv实现图片HDR功能
- opencv实现图片HDR功能
- MFC和OpenCV 对话框依次显示文件夹内的图片
- rdlc报表 打印图片功能如何实现