无法在win32中显示位图 [英] Can't display bitmap in win32

查看:165
本文介绍了无法在win32中显示位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我创建位图的方法

This is how i'm creating the bitmap

Bitmap bmp(100, 100, PixelFormat32bppARGB);





然后我使用LockBits来更改位图的一部分像素





Then I use LockBits to change a portion of the bitmap's pixels

void Example_LockBits2()
{
	UINT* pixels;
	// Lock a 50xs30 rectangular portion of the bitmap for writing.
	BitmapData bitmapData;
	Rect rect(20, 10, 50, 30);

	bmp.LockBits(
		&rect,
		ImageLockModeWrite,
		PixelFormat32bppARGB,
		&bitmapData);

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

	for (UINT row = 0; row < 30; ++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.  
	bmp.UnlockBits(&bitmapData);
}





最后尝试在WM_PAINT中显示它





And finally try to display it in WM_PAINT

case WM_PAINT:
	{
		Example_LockBits2();
		Graphics grap(GetDC(hwnd));
		grap.DrawImage(&bmp, 150, 100);
		break;
	}







因为我是GDI +的新手,我认为它可以是任何东西,特别是在创建Bitmap时,任何帮助都要理解




Since i'm new to GDI+ i think it could be anything, especially on the creation of the Bitmap, any help appreciated

推荐答案

你需要将bitmapData分配给Lockbits的返回值。



You need to assign bitmapData to the return value for Lockbits.

BitmapData bitmapData = bmp.LockBits(
    &rect,
    ImageLockModeWrite,
    PixelFormat32bppARGB,
    &bitmapData);


这篇关于无法在win32中显示位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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