关于打印图片的一个例子

DOCINFO docInfo;
 ZeroMemory(&docInfo, sizeof(docInfo));
 docInfo.cbSize = sizeof(docInfo);
 docInfo.lpszDocName = "GdiplusPrint";
 
 // Create a PRINTDLG structure, and initialize the appropriate fields.
 PRINTDLG printDlg;
 ZeroMemory(&printDlg, sizeof(printDlg));
 printDlg.lStructSize = sizeof(printDlg);
 printDlg.Flags = PD_RETURNDC;
 
 
 // Display a print dialog box.
 if(!PrintDlg(&printDlg))
 {
  printf("Failure/n");
 }
 else
 {
  // Now that PrintDlg has returned, a device context handle
  // for the chosen printer is in printDlg->hDC.
  //GetDefaultPrinter()
  CRect printClientRect;
  Rect printRect;
  int prHeight,prWidth,phyHeight,phyWidth;
  int hSize,wSize;
  
  CDC * printpCDC = CDC::FromHandle(printDlg.hDC);
  prWidth = printpCDC->GetDeviceCaps(HORZRES);
  prHeight = printpCDC->GetDeviceCaps(VERTRES);
  //phyHeight = printpCDC->GetDeviceCaps(PHYSICALHEIGHT);
  //phyWidth = printpCDC->GetDeviceCaps(PHYSICALWIDTH);
  
  wSize = printpCDC->GetDeviceCaps(HORZSIZE);
  hSize = printpCDC->GetDeviceCaps(VERTSIZE);
  
  int printx=printpCDC->GetDeviceCaps(LOGPIXELSX);
  int printy=printpCDC->GetDeviceCaps(LOGPIXELSY);
  int screenx=GetDC()->GetDeviceCaps(LOGPIXELSX);
  int screeny=GetDC()->GetDeviceCaps(LOGPIXELSY);
  
  float xRate = (float)((float)printx / (float)screenx);
  float yRate = (float)((float)printy / (float)screeny);
  
  //tmpwnd->GetClientRect(printClientRect);
  
  //printClientRect.left = (phyWidth - prWidth) / 2;
  //printClientRect.top = (phyHeight - prHeight) / 2;
  //printClientRect.right = printClientRect.left + prWidth;
  //printClientRect.bottom = printClientRect.top + prHeight;
  
  printClientRect.left = 0;
  printClientRect.top = 0;
  printClientRect.right = (float)(((float)wSize / (float)25.4)) * screenx;
  printClientRect.bottom = (float)(((float)hSize / (float)25.4)) * screeny;
  
  StartDoc(printDlg.hDC, &docInfo);
  StartPage(printDlg.hDC);
  Graphics graphics(printDlg.hDC);
  
  
 
  //prImage.GetVerticalResolution()
  //float wRateImage =  (float)prImage.GetHorizontalResolution();
  //float hRateImage =  (float)prImage.GetVerticalResolution();
  
 // GetImageRect(printClientRect,prImage.GetHeight(),prImage.GetWidth(),1,printRect);
  
  graphics.DrawImage(m_pbmpSrc, 0, 0);   //这里使用GDI+来打印到打印机的内容

  //graphics->DrawImage();
  EndPage(printDlg.hDC);
  EndDoc(printDlg.hDC);
 }
 if(printDlg.hDevMode)
  GlobalFree(printDlg.hDevMode);
 if(printDlg.hDevNames)
  GlobalFree(printDlg.hDevNames);
 if(printDlg.hDC)
  DeleteDC(printDlg.hDC); 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值