gpt4 book ai didi

C++ Gdiplus 单色像素值

转载 作者:行者123 更新时间:2023-11-28 06:20:24 24 4
gpt4 key购买 nike

我有一个单色位图。我将其用于碰撞检测。

// creates the monochrome bitmap
bmpTest = new Bitmap(200, 200, PixelFormat1bppIndexed);

// color and get the pixel color at point (x, y)
Color color;
bmpTest->GetPixel(110,110,&color);

// the only method I know of that I can get a 0 or 1 from.
int b = color.GetB();

// b is 0 when the color is black and 1 when it is not black as desired

有没有更快的方法?我只能在 Get A R G B() 值上使用它。我正在使用 GetB(),因为任何 ARGB 值都是 0 或 1,正确,但对我来说似乎很乱。

有没有一种方法可以从返回 0 或 1 的单色位图中读取一个字节? (是题)

最佳答案

您应该使用 LockBits() 方法来加快访问速度:

BitmapData bitmapData;
pBitmap->LockBits(&Rect(0,0,pBitmap->GetWidth(), pBitmap->GetHeight()), ImageLockModeWrite, PixelFormat32bppARGB, &bitmapData);

unsigned int *pRawBitmapOrig = (unsigned int*)bitmapData.Scan0; // for easy access and indexing

unsigned int curColor = pRawBitmapCopy[curY * bitmapData.Stride / 4 + curX];
int b = curColor & 0xff;
int g = (curColor & 0xff00) >> 8;
int r = (curColor & 0xff0000) >> 16;
int a = (curColor & 0xff000000) >> 24;

关于C++ Gdiplus 单色像素值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29397877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com