我想在一個位圖得到位,但我不斷收到這個輸出(PS我測試了整個陣列,以及。):爲什麼所有像素值的鎖定位返回-842150451?
-842150451 // Array before lockbits
-842150451 // Array after lockbits
這是我的代碼來獲取lockedBits。
BitmapData * getLockedBitmapData()
{
float squareSideLength = 50 * 4;
Bitmap * src = new Bitmap(squareSideLength , squareSideLength);
Graphics * graphics = Graphics::FromImage(solid);
SolidBrush blackBrush(Color(255, 0, 0, 0));
graphics->FillRectangle(&blackBrush, FLOAT_ZERO, FLOAT_ZERO, squareSideLength, squareSideLength);
int srcWidth = src->GetWidth();
int srcHeight = src->GetHeight();
UINT * pixels = new UINT[srcWidth * srcHeight];
// _RPT1(0, "%d\n", pixels[55]);
BitmapData * bitmapData = new BitmapData();
bitmapData->Width = srcWidth;
bitmapData->Height = srcHeight;
bitmapData->Stride = 4 * srcWidth;
bitmapData->PixelFormat = PixelFormat32bppARGB;
bitmapData->Scan0 = (VOID*) pixels;
bitmapData->Reserved = NULL;
src->LockBits(new Rect(0, 0, srcWidth, srcHeight),
ImageLockMode::ImageLockModeRead | ImageLockMode::ImageLockModeWrite,
src->GetPixelFormat(),
bitmapData);
// _RPT1(0, "%d\n", pixels[55]);
return bitmapData;
}
假設'-842150451'是一個32位整數,它在十六進制中的表示是'0xcdcdcdcd'。微軟的調試'malloc'使用這個值來標記未初始化的堆內存。 http://en.wikipedia.org/wiki/Magic_number_(programming) –