请高手指点调用API函数GetDIBits的问题

xiyi0616 2003-09-29 08:43:41
函数定义如下:
int GetDIBits(
HDC hdc, // handle to DC
HBITMAP hbmp, // handle to bitmap
UINT uStartScan, // first scan line to set
UINT cScanLines, // number of scan lines to copy
LPVOID lpvBits, // array for bitmap bits
LPBITMAPINFO lpbi, // bitmap data buffer
UINT uUsage // RGB or palette index
);
我这样调
GetDIBits(i_DC, i_hBitmap, starscan, numscan, Null, bitinfo, DIB_RGB_COLORS)总是返回0,未success。望不吝赐教!
...全文
65 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiyi0616 2003-09-30
  • 打赏
  • 举报
回复
我本来只想取图象信息,未找到合适api
xiyi0616 2003-09-30
  • 打赏
  • 举报
回复
谢谢上面的两位!
我找到另一个api函数 getobject,一次解决, 多谢!
bluebohe 2003-09-30
  • 打赏
  • 举报
回复
MSDN的解释
If the lpvBits parameter is non-NULL and the function succeeds, the return value is the number of scan lines copied from the bitmap.
你的lpvBits参数是NULL,所以返回零,呵呵
bluebohe 2003-09-30
  • 打赏
  • 举报
回复
如果是NULL的话,仅仅是填充bitinfo结构体,不返回缓冲区数组
bluebohe 2003-09-30
  • 打赏
  • 举报
回复
Null倒数第三个参数是返回的值,怎么可以是NULL
wuxfBrave 2003-09-30
  • 打赏
  • 举报
回复
HBITMAP CopyScreenToBitmap(LPRECT lpRect, BYTE *pData, BITMAPINFO *pHeader)
{
HDC hScrDC, hMemDC; // screen DC and memory DC
HBITMAP hBitmap, hOldBitmap; // handles to deice-dependent bitmaps
int nX, nY, nX2, nY2; // coordinates of rectangle to grab
int nWidth, nHeight; // DIB width and height
int xScrn, yScrn; // screen resolution

// check for an empty rectangle
if (IsRectEmpty(lpRect))
return NULL;

// create a DC for the screen and create
// a memory DC compatible to screen DC
hScrDC = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
hMemDC = CreateCompatibleDC(hScrDC);

// get points of rectangle to grab
nX = lpRect->left;
nY = lpRect->top;
nX2 = lpRect->right;
nY2 = lpRect->bottom;

// get screen resolution
xScrn = GetDeviceCaps(hScrDC, HORZRES);
yScrn = GetDeviceCaps(hScrDC, VERTRES);

//make sure bitmap rectangle is visible
if (nX < 0)
nX = 0;
if (nY < 0)
nY = 0;
if (nX2 > xScrn)
nX2 = xScrn;
if (nY2 > yScrn)
nY2 = yScrn;

nWidth = nX2 - nX;
nHeight = nY2 - nY;

// create a bitmap compatible with the screen DC
hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight);

// select new bitmap into memory DC
hOldBitmap = (HBITMAP) SelectObject(hMemDC, hBitmap);

// bitblt screen DC to memory DC
BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, nX, nY, SRCCOPY);

// select old bitmap back into memory DC and get handle to
// bitmap of the screen
hBitmap = (HBITMAP) SelectObject(hMemDC, hOldBitmap);

// Copy the bitmap data into the provided BYTE buffer
GetDIBits(hScrDC, hBitmap, 0, nHeight, pData, pHeader, DIB_RGB_COLORS);

// clean up
DeleteDC(hScrDC);
DeleteDC(hMemDC);

// return handle to the bitmap
return hBitmap;
}

看看上面的例子

15,980

社区成员

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

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