急救:我已经得到了一个 HBITMAP 对象,要什么方法才能获得该对象存放象素数据的具体地址,并对这些象素进行操作,谢谢!

damodem 2003-04-23 02:51:36
我已经得到了一个 HBITMAP 对象,要什么方法才能获得该对象存放象素数据的具体地址,并对这些象素进行操作,谢谢!
...全文
25 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
载舟之水 2003-05-14
  • 打赏
  • 举报
回复
给你一段参考代码,原则就是自己构造dib数据
来源于一个Gapi应用的例子
struct BGRColor
{
BGRColor() {}
BGRColor(byte R, byte G, byte B) : m_R(R), m_G(G), m_B(B) {}
byte m_B;
byte m_G;
byte m_R;
};

HBITMAP hResultBitmap;
BGRColor* pDIBits = GetDIBits(hBitmap, pBitmap->m_size, hResultBitmap);



//////////////////////////////以下为GetDIBits仿真////////////////////////
BGRColor* CSTGapiBuffer::GetDIBits(HBITMAP hBitmap, SIZE& size, HBITMAP& hResultBitmap)
{
// Getting bimap size
BITMAP bm;
GetObject(hBitmap, sizeof(BITMAP), &bm);

// Creating new bitmap and receive pointer to it's bits.
HBITMAP hTargetBitmap;
void *pBuffer;

int nCorrectedWidth = ((bm.bmWidth + 3) / 4 ) * 4;

// Initilize DIBINFO structure
DIBINFO dibInfo;
dibInfo.bmiHeader.biBitCount = 24;
dibInfo.bmiHeader.biClrImportant = 0;
dibInfo.bmiHeader.biClrUsed = 0;
dibInfo.bmiHeader.biCompression = 0;
dibInfo.bmiHeader.biHeight = bm.bmHeight;
dibInfo.bmiHeader.biPlanes = 1;
dibInfo.bmiHeader.biSize = 40;
dibInfo.bmiHeader.biSizeImage = nCorrectedWidth*bm.bmHeight*3;
dibInfo.bmiHeader.biWidth = nCorrectedWidth;
dibInfo.bmiHeader.biXPelsPerMeter = 3780;
dibInfo.bmiHeader.biYPelsPerMeter = 3780;
dibInfo.bmiColors[0].rgbBlue = 0;
dibInfo.bmiColors[0].rgbGreen = 0;
dibInfo.bmiColors[0].rgbRed = 0;
dibInfo.bmiColors[0].rgbReserved = 0;

// Create bitmap and receive pointer to points into pBuffer
HDC hDC = ::GetDC(NULL);
ASSERT(hDC);
hTargetBitmap = ::CreateDIBSection(
hDC,
(const BITMAPINFO*)dibInfo,
DIB_RGB_COLORS,
(void**)&pBuffer,
NULL,
0);

::ReleaseDC(NULL, hDC);


// Copy source bitmap into the target bitmap.

// Create 2 device contexts
HDC hMemDc = ::CreateCompatibleDC(NULL);
HDC hTargetDc = ::CreateCompatibleDC(NULL);

// Select source bitmap into one DC, target into another
HBITMAP hOldBitmap1 = (HBITMAP) ::SelectObject(hMemDc, hBitmap);
HBITMAP hOldBitmap2 = (HBITMAP) ::SelectObject(hTargetDc, hTargetBitmap);

// Copy source bitmap into the target one
::BitBlt(hTargetDc, 0, 0, bm.bmWidth, bm.bmHeight, hMemDc, 0, 0, SRCCOPY);

// Restore device contexts
::SelectObject(hMemDc, hOldBitmap1);
::SelectObject(hTargetDc, hOldBitmap2);

::DeleteDC(hMemDc);
::DeleteDC(hTargetDc);

// Here we can bitmap bits: pBuffer. Note:
// 1. pBuffer contains 3 bytes per point
// 2. Lines ane from the bottom to the top!
// 3. Points in the line are from the left to the right
// 4. Bytes in one point are BGR (blue, green, red) not RGB
// 5. pBuffer will be automatically deleted
// when delete hTargetBitmap

hResultBitmap = hTargetBitmap;
size.cx = bm.bmWidth;
size.cy = bm.bmHeight;
return (BGRColor*) pBuffer;
}
yayon 2003-05-14
  • 打赏
  • 举报
回复
能说一下如何DIB到DDB吗?
damodem 2003-04-29
  • 打赏
  • 举报
回复
help!!
damodem 2003-04-28
  • 打赏
  • 举报
回复
help!!
damodem 2003-04-26
  • 打赏
  • 举报
回复
help!!!1
damodem 2003-04-25
  • 打赏
  • 举报
回复
to :nbcool(载舟之水)
怎么转阿
我试了 GetDIBits,但wince 不支持
郁闷中阿 !!
载舟之水 2003-04-24
  • 打赏
  • 举报
回复
必须将hbitmap 转换为DIB数据才行,方法不难
damodem 2003-04-24
  • 打赏
  • 举报
回复
我说的是 WINCE 下,好像好难找到这种方法阿

19,500

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 嵌入开发(WinCE)
社区管理员
  • 嵌入开发(WinCE)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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