在位图图像打印时,出现图像过小,但在打印预览中能正常显示.以下是代码:
void CXcjc::DrawBMP(CDC* pDC,int iLogPixelX,int iLogPixelY,const char *strFileName){         CDC          MemDC; // 内存设备环境指针,在视的整个存在过程都将存在
         CBitmap         Bitmap,*pOldBmp;       
         CRect                Source, Dest; // 记录源位图尺寸和最终显示尺寸
         BITMAP         bm;
         if(MemDC.GetSafeHdc() == NULL)
         {
 HBITMAP hbitmap=(HBITMAP)LoadImage(0,strFileName,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE);
 if (hbitmap == NULL)
 return; 
 Bitmap.Attach(hbitmap);
 MemDC.CreateCompatibleDC(pDC);
 Bitmap.GetObject(sizeof(bm),&bm);
 pOldBmp=MemDC.SelectObject(&Bitmap);
 Source.top=0;
 Source.left=0;
 Source.right= bm.bmWidth;
 Source.bottom = bm.bmHeight;
 Dest = Source;
         }
         pDC->DPtoLP(&Dest);
         if(pDC->IsPrinting())
         {
 Dest.left=(int)(Dest.left*((double)pDC->GetDeviceCaps(LOGPIXELSX))/iLogPixelX);
 Dest.right=(int)(Dest.right*((double)pDC->GetDeviceCaps(LOGPIXELSX))/iLogPixelX);
 Dest.top=(int)(Dest.top*((double)pDC->GetDeviceCaps(LOGPIXELSY))/iLogPixelY);
 Dest.bottom=(int)(Dest.bottom*((double)pDC->GetDeviceCaps(LOGPIXELSY))/iLogPixelY);
         }
         pDC->StretchBlt(Dest.left+30, Dest.top+30, Dest.right, Dest.bottom,&MemDC, Source.left, Source.top, Source.right,Source.bottom, SRCCOPY);
         MemDC.SelectObject(pOldBmp);
         Bitmap.DeleteObject();
         MemDC.DeleteDC();
 return;
}
void CXcjc::DrawInfo(CDC &memDC, PRNINFO PrnInfo)
{
  int xP = GetDeviceCaps(memDC.m_hDC, LOGPIXELSX); //x方向每英寸像素点数
  int yP = GetDeviceCaps(memDC.m_hDC, LOGPIXELSY);
  DrawBMP(&memDC,xP,yP,".//image//df.bmp");}

总是找不出问题所在,请大家帮帮忙~~

解决方案 »

  1.   

    Using the MM_LOENGLISH Mapping Mode
    which treats each logical unit as 0.01 inches. In this mode, a stroke that is 100 logical units long is drawn as 1 inch long, no matter which device is used; each device driver determines how many device units are needed to draw a 1-inch stroke. Once Scribble uses MM_LOENGLISH mode, all coordinates used for GDI drawing are in hundredths of an inch, not pixels. As a result, the images that Scribble displays on the printer are the same size as the ones it displays on the screen. Recall that in Add Scrolling to Scribble, in Lesson 8, Scribble drawing was defined to be 800 logical units across and 900 logical units high; once you change the mapping mode, a drawing is 8 inches across and 9 inches high.Another feature of MM_LOENGLISH mode (as well as the other metric mapping modes) is that its y-axis runs in the opposite direction to that in MM_TEXT mode. In MM_TEXT mode, y-coordinates increase when you move down, but in all the metric mapping modes, y-coordinates increase when you move up.