StretchBlt不支持对内存HDC的操作么 怎么实现不了,GetDeviceCaps怎么检测,是这样么?

北漂17载 2004-05-07 10:31:43
StretchBlt不支持对内存HDC的操作么 怎么实现不了,GetDeviceCaps怎么检测,是这样么?
代码:
HDC htempDC;
htempDC=CreateCompatibleDC(memoryDC);
SetMapMode(htempDC,GetMapMode(memoryDC));
BitBlt(htempDC,0,0,bm.bmWidth,bm.bmHeight,htempDC,0,0,SRCCOPY);
int result;
result=GetDeviceCaps(memoryDC,RASTERCAPS);
if((RC_STRETCHBLT|result)>0)
{
MessageBox(hWnd,"Support the stretchbilet ","eee",MB_OK);
}//bm.bmWidth
StretchBlt(memoryDC,0,0,bm.bmWidth ,bm.bmHeight,htempDC,-bm.bmWidth,0,
bm.bmWidth,bm.bmHeight,SRCCOPY);
//BitBlt(memoryDC,0,0,bm.bmWidth,bm.bmHeight,hdc,0,0,SRCCOPY);
BitBlt(hdc,0,0,bm.bmWidth,bm.bmHeight,memoryDC,0,0,SRCCOPY);
if(GetLastError()!=0)
{
MessageBox(hWnd,"eeror vertical ","eee",MB_OK);
}
DeleteObject(htempDC);
其中:
HBITMAP hbmp;
BITMAP bm;
HDC memoryDC;
在sdk下
...全文
143 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
北漂17载 2004-05-08
  • 打赏
  • 举报
回复
我copy的代码有问题,关键的所在是两个 内存中的 HDC htempDC;HDC memoryDC; 在都CreateCompatibleDC() 后彼此间能否 进行 biltblt 和 StretchBlt 进行内容从一个中往另一个中操作 我的试验是不行,我觉得没有道理。
谢谢:cngdzhang() 我会研究一下 调色板的问题


cngdzhang 2004-05-07
  • 打赏
  • 举报
回复
给个例子,你看一下:
应该可以的,

函数 : DrawDIBSection(绘制DIBSection)
// hDC - 设备句柄
// hBitmap - DIB Section句柄
// xDest - 显示位图目标矩形的左上角X坐标
// yDest - 显示位图目标矩形的左上角Y坐标
void DrawDIBSection( HDC hDC, HBITMAP hBitmap, int xDest, int yDest )
{
HPALETTE hPal;

HDC hDCMem = ::CreateCompatibleDC( hDC );

// Create a logical palette for the bitmap
DIBSECTION ds;
BITMAPINFOHEADER &bmInfo = ds.dsBmih;
if( ::GetObject(hBitmap, sizeof(ds), &ds ) == 0 )
return; // Not a DIB Section

HGDIOBJ hBmpOld = ::SelectObject(hDCMem, hBitmap);

int nColors = bmInfo.biClrUsed ? bmInfo.biClrUsed : 1 << ds.dsBm.bmBitsPixel;

if( ::GetDeviceCaps(hDC, RASTERCAPS) & RC_PALETTE )
{
// Create a halftone palette if colors > 256.
if( nColors > 256 )
hPal = ::CreateHalftonePalette(hDC);
else
{
// Create the palette
RGBQUAD *pRGB = new RGBQUAD[nColors];

::GetDIBColorTable( hDCMem, 0, nColors, pRGB );

UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * nColors);
LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];

pLP->palVersion = 0x300;
pLP->palNumEntries = nColors;

for( int i=0; i < nColors; i++)
{
pLP->palPalEntry[i].peRed = pRGB[i].rgbRed;
pLP->palPalEntry[i].peGreen = pRGB[i].rgbGreen;
pLP->palPalEntry[i].peBlue = pRGB[i].rgbBlue;
pLP->palPalEntry[i].peFlags = 0;
}

hPal = ::CreatePalette( pLP );

delete[] pLP;
delete[] pRGB;
}

HPALETTE hPalOld = ::SelectPalette(hDC,hPal,FALSE);
::RealizePalette(hDC);
BitBlt(hDC,xDest,yDest,bmInfo.biWidth,bmInfo.biHeight,hDCMem,0,0,SRCCOPY);

::SelectPalette(hDC,hPalOld,FALSE);
// delete GDI objects
::DeleteObject(hPal);
}
else
BitBlt(hDC,xDest,yDest,bmInfo.biWidth,bmInfo.biHeight,hDCMem,0,0,SRCCOPY);

::SelectObject(hDCMem, hBmpOld);
::DeleteDC(hDCMem);
}

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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