[C++] Gdiplus: Convert Bitmap to Byte array
void BitmapToBytes(Gdiplus::Bitmap* bmp, BYTE** ppImageData)
{
Gdiplus::Rect rect(0, 0, bmp->GetWidth(), bmp->GetHeight());
//get the bitmap data
Gdiplus::BitmapData bitmapData;
if (Gdiplus::Ok == bmp->LockBits(
&rect, //A rectangle structure that specifies the portion of the Bitmap to lock.
Gdiplus::ImageLockModeRead | Gdiplus::ImageLockModeWrite, //ImageLockMode values that specifies the access level (read/write) for the Bitmap.
PixelFormat32bppARGB,// PixelFormat values that specifies the data format of the Bitmap.
&bitmapData //BitmapData that will contain the information about the lock operation.
))
{
//get the lenght of the bitmap data in bytes
int len = bitmapData.Height * std::abs(bitmapData.Stride);
if (*ppImageData)
{
delete[] * ppImageData;
}
*ppImageData = new BYTE[len];
memcpy(*ppImageData, bitmapData.Scan0, len);//copy it to an array of BYTEs
//...
//cleanup
bmp->UnlockBits(&bitmapData);
}
}