打印的问题 我要打印一个饼图,放在剪贴板里,打印预览已经看到了该饼图,但是为啥不能打印出该饼图?饼图颜色是彩色,打印机是单色 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CWnd::Printvoid Print( CDC* pDC, DWORD dwFlags ) const; 我问的就是你在OnDraw中通过什么dc成员函数画上去的饼图 pDC->SetMapMode( MM_TEXT); //pDC是 void CStatListView::OnDraw(CDC* pDC) if(m_hbitmap) //m_hbitmap是剪切下来的位图 { BITMAP bm; ::GetObject(m_hbitmap, sizeof(BITMAP), &bm); CSize chartSize(bm.bmWidth, bm.bmHeight); CDC dcMemory,dcScreen; dcScreen.Attach(::GetDC(NULL)); // create "from" device context and select the loaded bitmap into it dcMemory.CreateCompatibleDC(&dcScreen); dcMemory.SelectObject(p->m_hbitmap); // Print at 85% size within left/right margin CSize printSize; printSize.cx=(int)(rectPage.right*.85); printSize.cy=printSize.cx/chartSize.cx*chartSize.cy; CRect rect(0,0,printSize.cx,printSize.cy); // Print chart centered pDC->StretchBlt(500 ,rectPage.bottom-printSize.cy, printSize.cx, printSize.cy, &dcMemory, 0, 0, chartSize.cx, chartSize.cy, SRCCOPY); dcMemory.DeleteDC(); }} 可能是原點位置不對.所以看不到圖像.SetViewportOrg(0,500)或是其它值試試.也可以把y坐標改為負數試試 在啥地方放置SetViewportOrg(0,500) StretchBlt之前先用pDC->GetDeviceCaps(RASTERCAPS);看一下支不支持RC_STRETCHBLT pDC->SetMapMode( MM_TEXT); 后面 我加上测试 int xy=pDC->GetDeviceCaps(RASTERCAPS); if(xy==RC_STRETCHBLT) MessageBox("op");不显示op,是否表明不支持StretchBlt,我该如何改程序 pDC->SetMapMode( MM_TEXT); 后面是啥意思,如何改 if((xy&RC_STRETCHBLT)==RC_STRETCHBLT) 薄荷,我测试过了,if((xy&RC_STRETCHBLT)==RC_STRETCHBLT)是成立的,表明支持StretchBlt为啥打印预览已经看到了该饼图,不能打印出该饼图?奇怪! 还有不知道你if((xy&RC_STRETCHBLT)==RC_STRETCHBLT)是不是在打印而不是在预览下返回真的 现在我知道了,不知道你还有没有兴趣听,主要原因是你的位图是DDB,和打印设备不兼容,你要把它转化成DIB位图,通过StretchDIBits打印下面是一些转化和打印的代码void Draw(HDC hDC,HBITMAP hBmp,double dScaleX,double dScaleY,int iX,int iY,int iWidth=0,int iLength=0){ HPALETTE hPal; BITMAP bm; BITMAPINFOHEADER bi; LPBITMAPINFOHEADER lpbi; DWORD dwLen; HANDLE hDIB; HANDLE handle; HDC hDC1; if(GetDeviceCaps(hDC,RASTERCAPS) & RC_PALETTE ) { UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256); LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize]; pLP->palVersion = 0x300; pLP->palNumEntries =GetSystemPaletteEntries( hDC, 0, 255, pLP->palPalEntry ); hPal=CreatePalette(pLP ); delete[] pLP; } if (hPal==NULL) hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE); ::GetObject(hBmp,sizeof(bm),(LPSTR)&bm); bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = bm.bmWidth; bi.biHeight = bm.bmHeight; bi.biPlanes = 1; bi.biBitCount = bm.bmPlanes * bm.bmBitsPixel; bi.biCompression = BI_RGB; bi.biSizeImage = 0; bi.biXPelsPerMeter = 0; bi.biYPelsPerMeter = 0; bi.biClrUsed = 0; bi.biClrImportant = 0; int nColors = (1 << bi.biBitCount); if( nColors > 256 ) nColors = 0; dwLen = bi.biSize + nColors * sizeof(RGBQUAD); hDC1 = ::GetDC(NULL); hPal = SelectPalette(hDC1,hPal,FALSE); RealizePalette(hDC1); hDIB = GlobalAlloc(GMEM_FIXED,dwLen); if (!hDIB) { SelectPalette(hDC1,hPal,FALSE); ::ReleaseDC(NULL,hDC1); DeleteObject(hPal); return ; } lpbi = (LPBITMAPINFOHEADER)hDIB; *lpbi = bi; ::GetDIBits(hDC1, hBmp, 0L, (DWORD)bi.biHeight, (LPBYTE)NULL, (LPBITMAPINFO)lpbi, (DWORD)DIB_RGB_COLORS); bi = *lpbi; if (bi.biSizeImage == 0) bi.biSizeImage = ((((bi.biWidth * bi.biBitCount) + 31) & ~31) / 8)* bi.biHeight; dwLen += bi.biSizeImage; if (handle = GlobalReAlloc(hDIB, dwLen, GMEM_MOVEABLE)) hDIB = handle; else { GlobalFree(hDIB); SelectPalette(hDC1,hPal,FALSE); ::ReleaseDC(NULL,hDC1); DeleteObject(hPal); return ; } lpbi = (LPBITMAPINFOHEADER)hDIB; BOOL bGotBits = GetDIBits( hDC1, hBmp,0L,(DWORD)bi.biHeight,(LPBYTE)lpbi+ (bi.biSize + nColors * sizeof(RGBQUAD)), (LPBITMAPINFO)lpbi,(DWORD)DIB_RGB_COLORS); if( !bGotBits ) { GlobalFree(hDIB); SelectPalette(hDC1,hPal,FALSE); ::ReleaseDC(NULL,hDC1); DeleteObject(hPal); return; } if(iWidth==0||iLength==0) { iWidth=lpbi->biWidth; iLength=lpbi->biHeight; iWidth=(int)(dScaleX*iWidth); iLength=(int)(iLength*dScaleY); } StretchDIBits(hDC,iX,iY,iWidth,iLength,0,0,lpbi->biWidth,lpbi->biHeight,(LPBYTE)lpbi // address for bitmap bits + (bi.biSize + nColors * sizeof(RGBQUAD)),(LPBITMAPINFO)lpbi,DIB_RGB_COLORS,SRCCOPY); SelectPalette(hDC1,hPal,FALSE); ::ReleaseDC(NULL,hDC1); DeleteObject(hDIB); DeleteObject(hPal);} 如何编写一个测试系统的问题 CEditBox 换行乱码问题 大家好 问个问题 简单线程问题,传入两个参数 请问<VC技术内幕>中ex23b的工程是怎么建立的? 0x00000fd stack over flow WIN2000下 VC如何封锁“CTRL+ALT+DEL”(有分) 如何通过ID得到控件的柄句? 请教大侠,如何判断两个RGB值是不同明暗的同一颜色。 我不知道有几个人能达到程序人生的境界?? 怎样动态更改属性页面 如何在程序里面把最小化的qq显示出来?
void Print( CDC* pDC, DWORD dwFlags ) const;
if(m_hbitmap) //m_hbitmap是剪切下来的位图
{
BITMAP bm;
::GetObject(m_hbitmap, sizeof(BITMAP), &bm);
CSize chartSize(bm.bmWidth, bm.bmHeight); CDC dcMemory,dcScreen;
dcScreen.Attach(::GetDC(NULL));
// create "from" device context and select the loaded bitmap into it
dcMemory.CreateCompatibleDC(&dcScreen);
dcMemory.SelectObject(p->m_hbitmap);
// Print at 85% size within left/right margin
CSize printSize;
printSize.cx=(int)(rectPage.right*.85);
printSize.cy=printSize.cx/chartSize.cx*chartSize.cy;
CRect rect(0,0,printSize.cx,printSize.cy); // Print chart centered
pDC->StretchBlt(500 ,rectPage.bottom-printSize.cy, printSize.cx, printSize.cy, &dcMemory, 0, 0, chartSize.cx, chartSize.cy, SRCCOPY);
dcMemory.DeleteDC();
}
}
SetViewportOrg(0,500)或是其它值試試.也可以把y坐標改為負數試試
if(xy==RC_STRETCHBLT)
MessageBox("op");
不显示op,是否表明不支持StretchBlt,我该如何改程序
是啥意思,如何改
是成立的,表明支持StretchBlt为啥打印预览已经看到了该饼图,不能打印出该饼图?奇怪!
下面是一些转化和打印的代码
void Draw(HDC hDC,HBITMAP hBmp,double dScaleX,double dScaleY,int iX,int iY,int iWidth=0,int iLength=0)
{
HPALETTE hPal;
BITMAP bm;
BITMAPINFOHEADER bi;
LPBITMAPINFOHEADER lpbi;
DWORD dwLen;
HANDLE hDIB;
HANDLE handle;
HDC hDC1;
if(GetDeviceCaps(hDC,RASTERCAPS) & RC_PALETTE )
{
UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256);
LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];
pLP->palVersion = 0x300;
pLP->palNumEntries =GetSystemPaletteEntries( hDC, 0, 255, pLP->palPalEntry );
hPal=CreatePalette(pLP );
delete[] pLP;
}
if (hPal==NULL) hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE);
::GetObject(hBmp,sizeof(bm),(LPSTR)&bm);
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = bm.bmWidth;
bi.biHeight = bm.bmHeight;
bi.biPlanes = 1;
bi.biBitCount = bm.bmPlanes * bm.bmBitsPixel;
bi.biCompression = BI_RGB;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
int nColors = (1 << bi.biBitCount);
if( nColors > 256 )
nColors = 0;
dwLen = bi.biSize + nColors * sizeof(RGBQUAD);
hDC1 = ::GetDC(NULL);
hPal = SelectPalette(hDC1,hPal,FALSE);
RealizePalette(hDC1);
hDIB = GlobalAlloc(GMEM_FIXED,dwLen);
if (!hDIB)
{
SelectPalette(hDC1,hPal,FALSE);
::ReleaseDC(NULL,hDC1);
DeleteObject(hPal);
return ;
}
lpbi = (LPBITMAPINFOHEADER)hDIB;
*lpbi = bi;
::GetDIBits(hDC1, hBmp, 0L, (DWORD)bi.biHeight,
(LPBYTE)NULL, (LPBITMAPINFO)lpbi, (DWORD)DIB_RGB_COLORS);
bi = *lpbi;
if (bi.biSizeImage == 0)
bi.biSizeImage = ((((bi.biWidth * bi.biBitCount) + 31) & ~31) / 8)* bi.biHeight;
dwLen += bi.biSizeImage;
if (handle = GlobalReAlloc(hDIB, dwLen, GMEM_MOVEABLE))
hDIB = handle;
else
{
GlobalFree(hDIB);
SelectPalette(hDC1,hPal,FALSE);
::ReleaseDC(NULL,hDC1);
DeleteObject(hPal);
return ;
}
lpbi = (LPBITMAPINFOHEADER)hDIB;
BOOL bGotBits = GetDIBits( hDC1, hBmp,0L,(DWORD)bi.biHeight,(LPBYTE)lpbi+ (bi.biSize + nColors * sizeof(RGBQUAD)),
(LPBITMAPINFO)lpbi,(DWORD)DIB_RGB_COLORS);
if( !bGotBits )
{
GlobalFree(hDIB);
SelectPalette(hDC1,hPal,FALSE);
::ReleaseDC(NULL,hDC1);
DeleteObject(hPal);
return;
}
if(iWidth==0||iLength==0)
{
iWidth=lpbi->biWidth;
iLength=lpbi->biHeight;
iWidth=(int)(dScaleX*iWidth);
iLength=(int)(iLength*dScaleY);
}
StretchDIBits(hDC,iX,iY,iWidth,iLength,0,0,lpbi->biWidth,lpbi->biHeight,(LPBYTE)lpbi // address for bitmap bits
+ (bi.biSize + nColors * sizeof(RGBQUAD)),(LPBITMAPINFO)lpbi,DIB_RGB_COLORS,SRCCOPY);
SelectPalette(hDC1,hPal,FALSE);
::ReleaseDC(NULL,hDC1);
DeleteObject(hDIB);
DeleteObject(hPal);
}