• 读取图片并打印图片


    void PrintBitmap(LPCTSTR filename) {
     CPrintDialog printDlg(FALSE);
     printDlg.GetDefaults(); 
     // Or get from user:
     // if (printDlg.DoModal() == IDCANCEL)   
     //        return; 
     CDC dc;
     if (!dc.Attach(printDlg.GetPrinterDC())) {
      AfxMessageBox(_T("No printer found!")); return;
     } 
     
     dc.m_bPrinting = TRUE; 
     DOCINFO di;    
     // Initialise print document details
     ::ZeroMemory (&di, sizeof (DOCINFO));
     di.cbSize = sizeof (DOCINFO);
     di.lpszDocName = filename; 
     BOOL bPrintingOK = dc.StartDoc(&di); // Begin a new print job 
     // Get the printing extents
     // and store in the m_rectDraw field of a 
     // CPrintInfo object
     CPrintInfo Info;
     Info.SetMaxPage(1); // just one page 
     int maxw = dc.GetDeviceCaps(HORZRES);
     int maxh = dc.GetDeviceCaps(VERTRES); 
     Info.m_rectDraw.SetRect(0, 0, maxw, maxh); 
     for (UINT page = Info.GetMinPage(); page <= 
          Info.GetMaxPage() && bPrintingOK; page++) {
      dc.StartPage();    // begin new page
      Info.m_nCurPage = page;
      CBitmap bitmap;
      // LoadImage does the trick here, it creates a DIB section
      // You can also use a resource here
      // by using MAKEINTRESOURCE() ... etc. 
      if(!bitmap.Attach(::LoadImage(
       ::GetModuleHandle(NULL), filename, IMAGE_BITMAP, 0, 0, 
       LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE))) {
        AfxMessageBox(_T("Error loading bitmap!")); return;
       } 
       BITMAP bm;
       bitmap.GetBitmap(&bm);
       int w = bm.bmWidth; 
       int h = bm.bmHeight; 
       // create memory device context
       CDC memDC; 
       memDC.CreateCompatibleDC(&dc);
       CBitmap *pBmp = memDC.SelectObject(&bitmap);
       memDC.SetMapMode(dc.GetMapMode());
       dc.SetStretchBltMode(HALFTONE);
       // now stretchblt to maximum width on page
       dc.StretchBlt(0, 0, maxw, maxh, &memDC, 0, 0, w, h, SRCCOPY); 
       // clean up
       memDC.SelectObject(pBmp);
       bPrintingOK = (dc.EndPage() > 0);   // end page
     } 
     if (bPrintingOK)
       dc.EndDoc(); // end a print job
     else dc.AbortDoc();           // abort job. 
    }

    http://blog.csdn.net/kingmax54212008/article/details/77141553
  • 相关阅读:
    随笔
    3.1作业
    关于JavaDate数据返回到前端变数字的问题(并引申到前后端时间的传输)
    utf-8转换为base64
    base64转换为utf-8
    Java Web基础——jsp调用动态界面
    Java Web基础——JSP指令标记
    2020软件工程最后一次作业
    软件工程第二次结对作业
    软件工程第三次作业
  • 原文地址:https://www.cnblogs.com/dengpeng1004/p/7448666.html
Copyright © 2020-2023  润新知