Here is how I would do it using the GDIPlus Bitmap.LockBits method defined in the GdiPlusBitmap.h header:
Gdiplus::BitmapData bitmapData;
Gdiplus::Rect rect(0, 0, bitmap.GetWidth(), bitmap.GetHeight());
if(Gdiplus::Ok == bitmap.LockBits(
&rect,
Gdiplus::ImageLockModeRead | Gdiplus::ImageLockModeWrite,
bitmap.GetPixelFormat(),
&bitmapData
))
{
int len = bitmapData.Height * std::abs(bitmapData.Stride);
BYTE* buffer = new BYTE[len];
memcpy(bitmapData.Scan0, buffer, len);
pBitmapImageRot.UnlockBits(&bitmapData);
delete []buffer;
}
source
share