锁定位功能“触发断点” [英] Lockbits function "triggers breakpoint"

查看:85
本文介绍了锁定位功能“触发断点”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Bitmap *pbmp     //global variable

//trying to make a buffer for the constructor, but it doesn't work as expected
byte *bytes = new byte[1000];
	for (size_t i = 0; i < 1000; i++)
	{
		bytes[i] = 255;
	}
	Bitmap bmp(100, 100, 500, PixelFormat32bppARGB, bytes);





以下是我在运行时创建位图的方法,因为我需要改变它的一小部分我在WM_PAINT中使用这个函数:





Here is how i'm creating a bitmap at runtime, and since I need to change little portions of it i'm using this function inside WM_PAINT :

void LockBits()
{
	UINT* pixels;
	// Lock a 50xs30 rectangular portion of the bitmap for writing.
	BitmapData bitmapData;
	Rect rect(20, 10, 50, 60);
			
	pbmp->LockBits( &rect, ImageLockModeWrite, PixelFormat32bppARGB, &bitmapData);

	// Write to the temporary buffer provided by LockBits.
	pixels = (UINT*)bitmapData.Scan0;

	for (UINT row = 0; row < 60; ++row)
		for (UINT col = 0; col < 50; ++col)
		{
			pixels[row * bitmapData.Stride / 4 + col] = 0xff00ff00;
		}

	// Commit the changes, and unlock the 50x30 portion of the bitmap.  
	pbmp->UnlockBits(&bitmapData);
}


//********************************************************************************
case WM_PAINT:
{
    LockBits();
    Graphics grap(GetDC(hwnd));
    grap.DrawImage(&(*pbmp), 150, 100);
}
break;





尽快当我运行该程序时,它可以工作(显示更改的位图),但在Myprogram.exe触发了断点之后立即显示。然后指向WinMain -DispatchMessage(& msg)内的行; -





编辑:看来我没有给位图构造函数提供了足够大的缓冲区,将其设置为40000就可以了。但对于100x100位图来说,这不是一个太大的数字吗?我该如何计算缓冲区大小? width * height * 4(因为像素格式是32位)?



As soon as I run the program, it works (display the changed bitmap) but immediately after "Myprogram.exe has triggered a breakpoint." and then points to the line inside WinMain -DispatchMessage(&msg);-


It appears that I didn't gave a big enough buffer to the bitmap constructor, setting it to 40000 does the trick. But isn't it a way too big number for a 100x100 bitmap ? How should I calculate buffer size ? width * height * 4 (since pixel format is 32bits) ?

推荐答案

100x100x4 = 40000,为什么你确实需要那么多内存呢。



对于bufsize,你经常需要将宽度四舍五入(但应该在文档中)。

100x100x4 = 40000, why you indeed need that much memory for it.

For bufsize, you often need to round the width up to 4 (but that should be in the documentation).
bufsize = ROUNDUP_TO_4(width) * height * Bpp;



其中Bpp =每像素字节数,ROUNDUP_TO_4可能是


where Bpp = Bytes per pixel, and ROUNDUP_TO_4 could be

#define ROUNDUP_TO_4(x) (((x)+3)&~3)


这篇关于锁定位功能“触发断点”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆