VC图像打印的问题,找了一天了,各位给看看 解决了我有多少分给多少!

kikipu 2007-10-27 03:49:06
HBITMAP hBitmap=::LoadBitmap(AfxGetInstanceHandle(),(LPCTSTR)IDB_PAGEONE);
BITMAP bitmap;
::GetObject(hBitmap,sizeof(BITMAP),&bitmap);
double dScale=(double)m_cxWidth/bitmap.bmWidth;
int nScaledWidth=m_cxWidth;
int nScaledHeight=(int)(bitmap.bmHeight*dScale);



HDC dcMem;
dcMem=::CreateCompatibleDC(pDC->m_hDC);
HBITMAP hOldBmp=(HBITMAP)::SelectObject(dcMem,hBitmap);

int nVertCenterPos = pDC->GetDeviceCaps (VERTRES) / 2;
::StretchBlt(pDC->m_hDC,m_cxOffset/2,(4 + PRINTMARGIN)*m_cyPrinter /2,nScaledWidth+m_cxOffset,nScaledHeight+(4 + PRINTMARGIN)*m_cyPrinter,dcMem,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);
这个是图像显示的过程,用预览可以看到,但是只有一打印还是空白,而且图像有个最大值 不能再大了。
...全文
224 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lllxy 2007-11-15
  • 打赏
  • 举报
回复
接分
e_feeling 2007-11-12
  • 打赏
  • 举报
回复
关注
kikipu 2007-11-06
  • 打赏
  • 举报
回复
我咋不能加分呢?
kikipu 2007-11-06
  • 打赏
  • 举报
回复
谢谢 各位了!终于搞好了 是内存绘图的问题!
HBITMAP hBitmap=(HBITMAP)LoadImage(0,_T(".\\config\\page1.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE | LR_CREATEDIBSECTION);
BITMAP bitmap;
if (MemDC.GetSafeHdc() == NULL)
{
Bitmap.Attach(hBitmap);
MemDC.CreateCompatibleDC(pDC);
Bitmap.GetObject(sizeof(bitmap),&bitmap);
pOldBmp=MemDC.SelectObject(&Bitmap);
Source.top=0;
Source.left=0;
Source.right= bitmap.bmWidth;
Source.bottom = bitmap.bmHeight;
Dest = Source;
}
pDC->DPtoLP(&Dest);
pDC->StretchBlt(Dest.left, Dest.top, Dest.right, Dest.bottom,&MemDC,Source.left, Source.top, Source.right,Source.bottom,SRCCOPY);
lyg_zy 2007-10-30
  • 打赏
  • 举报
回复
参考mfc的打印流程和源代码修改你的打印代码吧。
凤矶 2007-10-29
  • 打赏
  • 举报
回复
你确定StretchBlt时没有超出viewport范围?
	HANDLE hPrinter;
char * const PrinterName = "hp 7900";

if ( !OpenPrinter(PrinterName, &hPrinter, NULL) )
return ;
int nSize = DocumentProperties(NULL, hPrinter, PrinterName, NULL, NULL, 0);
DEVMODE * pDevMode = (DEVMODE *) new char[nSize];
if ( pDevMode==NULL )
return ;

// ask driver to initialize a devmode structure
DocumentProperties(NULL, hPrinter, PrinterName, pDevMode, NULL, DM_OUT_BUFFER);
pDevMode->dmPaperSize = DMPAPER_A4;
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
DocumentProperties(NULL, hPrinter, PrinterName, NULL, pDevMode, DM_OUT_BUFFER);
// default preparation
HDC hDC = CreateDC(NULL, PrinterName, NULL, pDevMode);
SaveDC (hDC);
SetMapMode(hDC, MM_TEXT);

static DOCINFO di = { sizeof (DOCINFO), TEXT ("Print1: Printing") } ;
HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, "01.bmp", IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
BITMAP bitmap;
::GetObject(hBitmap,sizeof(BITMAP),&bitmap);

int cxPage = GetDeviceCaps (hDC, HORZRES);
int cyPage = GetDeviceCaps (hDC, VERTRES);

float scale;

if((float)cxPage/(float)(bitmap.bmWidth) < (float)cyPage/(float)(bitmap.bmHeight))
{
scale = (float)cxPage/(float)(bitmap.bmWidth);
}
else
{
scale = (float)cyPage/(float)(bitmap.bmHeight);
}

StartDoc (hDC, &di);
StartPage (hDC);

HDC dcMem;
dcMem=::CreateCompatibleDC(hDC);
SelectObject(dcMem, hBitmap);

// 按比例缩放
::StretchBlt(hDC,0,0,bitmap.bmWidth*scale,bitmap.bmHeight*scale,dcMem,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);
// ::StretchBlt(hDC,0,0,cxPage,cyPage,dcMem,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);
delete pDevMode;
EndPage (hDC);
EndDoc (hDC);
RestoreDC (hDC, -1);
DeleteDC(hDC);
何日复西归 2007-10-28
  • 打赏
  • 举报
回复
看看打印之后,是否又引发了擦除过程。
试一试用mfc做,类似我的代码:
BITMAP s_bitmap;
CBitmap bitmap;
memset(&s_bitmap,0,sizeof(BITMAP));
if(!bitmap.LoadBitmap(IDB_PAGEONE))
{
AfxMessageBox("位图加载失败");
return;
}
bitmap.GetBitmap(&s_bitmap);
CDC compatibleDC;
compatibleDC.CreateCompatibleDC(pDC);
compatibleDC.SelectObject(&bitmap);
pDC->BitBlt(0,0,s_bitmap.bmWidth,s_bitmap.bmHeight,&compatibleDC,0,0,SRCCOPY);
Elysium 2007-10-27
  • 打赏
  • 举报
回复
PrintDC
zhuwuwei 2007-10-27
  • 打赏
  • 举报
回复
打印dc传对了么?

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧