能获得DC的句柄吗? COLORREF GetPixel( HDC hdc, // handle to DC int nXPos, // x-coordinate of pixel int nYPos // y-coordinate of pixel );不行的话只有读取位图数据了: LONG GetBitmapBits( HBITMAP hbmp, // handle to bitmap LONG cbBuffer, // number of bytes to copy LPVOID lpvBits // buffer to receive bits );参考: http://blog.csdn.net/pomelowu/archive/2005/01/10/247251.aspx
to pomelowu(羽战士) : 可以取得DC,但我是想把整张位图的所有像素颜色值取下,因为像素点太多了,如果频繁调用GetPixel()效率提不上去,我是想通过截取客户区的某区域的位图,在内存的位图句柄内获取所有点的的像素,从而提升效率!!我查过一下MSDN GetBitmapBits() 好像已不提倡用了取而代之的是GetDIBits(),但我却不知道这个函数该如何用,能给去一些具体的实例吗??那个链接好像连不上去的!!谢谢你的回复!!!
COLORREF GetPixel(
HDC hdc, // handle to DC
int nXPos, // x-coordinate of pixel
int nYPos // y-coordinate of pixel
);不行的话只有读取位图数据了:
LONG GetBitmapBits(
HBITMAP hbmp, // handle to bitmap
LONG cbBuffer, // number of bytes to copy
LPVOID lpvBits // buffer to receive bits
);参考:
http://blog.csdn.net/pomelowu/archive/2005/01/10/247251.aspx
可以取得DC,但我是想把整张位图的所有像素颜色值取下,因为像素点太多了,如果频繁调用GetPixel()效率提不上去,我是想通过截取客户区的某区域的位图,在内存的位图句柄内获取所有点的的像素,从而提升效率!!我查过一下MSDN GetBitmapBits() 好像已不提倡用了取而代之的是GetDIBits(),但我却不知道这个函数该如何用,能给去一些具体的实例吗??那个链接好像连不上去的!!谢谢你的回复!!!
你上我的blog,
http://blog.csdn.net/pomelowu
找 MFC下截屏 & 灰度显示 那篇文章。
{
mov ecx, pColBuffer // 整个过程中 ecx 一直存放着pColBuffer的指针 // 纵向循环
mov dword ptr [y],0
jmp VerCmp LoopStep1: add y,1 VerCmp: mov eax,dword ptr [y]
cmp eax,dword ptr [nHeight]
jge end // 结束 // 横向循环
mov dword ptr [x],0
jmp HorCmp LoopStep2: add x,1 HorCmp: mov eax,dword ptr [x]
cmp eax,dword ptr [nWidth]
jge BufOffset // 取出16bit的颜色值
mov edx,x
mov eax,pSurBuf
mov bx,WORD ptr [eax+edx*2]
// 取红色
mov ax, bx
and ax, 0xf800 // R mask
mov BYTE PTR [ecx], ah
inc ecx
// 取绿色
mov ax, bx
and ax, 0x7e0 // G mask
shr ax, 3
mov BYTE PTR [ecx], al
inc ecx
// 取蓝色
mov ax, bx
and ax, 0x1f // B mask
shl ax, 3
mov BYTE PTR [ecx], al
inc ecx
// mov pColBuffer, ecx
jmp LoopStep2 // 修正指向Surface的颜色存储指针
BufOffset: mov eax , nHalfPitch
shl eax, 1
add pSurBuf, eax
jmp LoopStep1
end:
}