HDC BITMAP BitBlt判断位图是否为黑色GetDIBits

关于GDI,怎样通过 HDC 获取 DC 当前的 HBITMAP

https://zhidao.baidu.com/question/1302472552069867299.html

HBITMAP bmp=GetCurrentObject(hdc,OBJ_BITMAP);

win32 位图 Bitmap 和 Bitblt 演示

https://blog.csdn.net/wowocpp/article/details/80915162

GetObject(_hbitmap, sizeof(bmp), &bmp)返回bmp.bmBits为NULL

https://www.cnblogs.com/mumuliang/archive/2012/06/05/2536533.html

对使用其他函数创建的HBITMAP使用GetObject(),函数成功的情况对应2.输出参数只是保存了图像数据基本信息例如长宽颜色格式等的BITMAP。获取图像数据需要使用GetDIBBits或GetBitmapBits

http://doc.okbase.net/chunyexiyu/archive/100274.html

http://www.voidcn.com/article/p-rpwsmgtt-rz.html

要获取屏幕的像素大小要使用GetSystemMetrics函数,该函数用于得到被定义的系统数据或者系统配置信息。支持多个参数,以SM_CXSCREEN和SM_CYSCREEN得到屏幕的宽和高为例:

https://blog.csdn.net/chenlycly/article/details/39034547?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-7.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-7.control

关于Bitmap像素颜色的判断

https://blog.csdn.net/weixin_30518397/article/details/97840865

请教高手:如何以HBITMAP判断位图是否为黑色。在线等待,谢谢

https://bbs.csdn.net/topics/50457558

BitBlt

https://blog.csdn.net/z0203153008/article/details/5937571/

 

BITMAP结构体

https://blog.csdn.net/danelumax2/article/details/8639227

typedef struct tagBITMAP{
LONG bmType; // 位图类型,必须为0
LONG bmWidth; // 位图宽度
LONG bmHeight; // 位图高度
LONG bmWidthBytes; //每一行像素所在的byte数
WORD bmPlanes; //颜色平面数
WORD bmBitsPixel; //像素的位数
LPVOID bmBits; //位图内存 指针
}BITMAP;
————————————————
版权声明:本文为CSDN博主「danelumax2」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/danelumax2/article/details/8639227

VC++下如何载入一张位图并获取该位图的像素值

https://zhidao.baidu.com/question/132759420.html

HBITMAP hBmp = (HBITMAP)LoadImage( NULL , "z:\\bg4.bmp" , IMAGE_BITMAP , 0 , 0 , LR_CREATEDIBSECTION | LR_LOADFROMFILE);
if (hBmp != NULL)
{
BITMAP bmp = {0};
int ret = GetObject( hBmp , sizeof(BITMAP) , &bmp );
if (ret)
{
TRACE( "Width = %d Height = %d BitsPerPixel = %d\n" , bmp.bmWidth , bmp.bmHeight , bmp.bmBitsPixel );
BYTE* pPixel = (BYTE*)bmp.bmBits; //指向BMP像素的指针
int x = 1439 , y = 899; //指定要获取像素的坐标 规定图片左上角坐标为0,0
BYTE *pOffset = pPixel + (bmp.bmHeight - 1) * bmp.bmWidthBytes; //指向最后一行像素数据
pOffset = (pOffset - y * bmp.bmWidthBytes) + x * bmp.bmBitsPixel / 8; //指向指定像素位置
DWORD rgb = 0;
memcpy( &rgb , pOffset , bmp.bmBitsPixel / 8 );
TRACE( "(x = %d y = %d) = %u\n" , x , y , rgb );
}
DeleteObject( hBmp );
hBmp = NULL;
ZeroMemory( &bmp , sizeof(bmp) );
}
上面代码里的rgb就是你要的像素了
如果你是在对话框之类的处理的话可以用类似下面的代码实现
CDC* pDc = GetDC();

 

CBitmap、HBITMAP、BITMAP相互转换

https://blog.csdn.net/piaopiaopiaopiaopiao/article/details/41554569

BITMAP bm;
::GetObject(hBitmap, sizeof(bm), &bm);
void CounterThread::run() { int count = 0; while (true) { // 每1秒钟加一并发送信号 msleep(10); HDC hdcScreen = GetDC(NULL); // 获取整个屏幕的设备上下文 HDC hdcMemDC = CreateCompatibleDC(hdcScreen); // 创建内存设备上下文 int width = GetSystemMetrics(SM_CXSCREEN); // 获取屏幕宽度 int height = GetSystemMetrics(SM_CYSCREEN); // 获取屏幕高度 HBITMAP hbmScreen ,hbmOldBitmap ; hbmScreen= CreateCompatibleBitmap(hdcScreen, width, height); // 创建与屏幕设备上下文兼容的位图 hbmOldBitmap= (HBITMAP)SelectObject(hdcMemDC, hbmScreen); // 将位图选入内存设备上下文 BitBlt(hdcMemDC, 0, 0, width, height, hdcScreen, 0, 0, SRCCOPY); // 将屏幕内容绘制到位图BITMAP bmpScreen; GetObject(hbmScreen, sizeof(BITMAP), &bmpScreen); // 获取位图信息 BITMAPINFOHEADER bi; bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = bmpScreen.bmWidth; bi.biHeight = bmpScreen.bmHeight; bi.biPlanes = 1; bi.biBitCount = 32; bi.biCompression = BI_RGB; bi.biSizeImage = 0; bi.biXPelsPerMeter = 0; bi.biYPelsPerMeter = 0; bi.biClrUsed = 0; bi.biClrImportant = 0; BYTE pBits = new BYTE[bmpScreen.bmWidth * bmpScreen.bmHeight * 4]; GetDIBits(hdcMemDC, hbmScreen, 0, bmpScreen.bmHeight, pBits, (BITMAPINFO)&bi, DIB_RGB_COLORS); // 将位图数据读取到字节数组中 QImage image(pBits, bmpScreen.bmWidth, bmpScreen.bmHeight, QImage::Format_ARGB32); image = image.convertToFormat(QImage::Format_RGB888).mirrored(false, true); QPixmap pixmap = QPixmap::fromImage(image); // 将字节数组转换为 QPixmap 对象 emit setpix( pixmap); emit countChanged(count); SelectObject(hdcMemDC, hbmOldBitmap); DeleteObject(hbmScreen); DeleteDC(hdcMemDC); ReleaseDC(NULL, hdcScreen); } }这是出错程序,运行一段时间报报错 DWM故障怎么解决该如何改?
最新发布
06-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值