CImage转换Gdiplus::Bitmap

Gdiplus::Bitmap* CImage2Image(const CImage* pImage )
{
if(!pImage)
return NULL;


Gdiplus::Bitmap* image = new Gdiplus::Bitmap( pImage->GetWidth(), pImage->GetHeight() );
Gdiplus::Rect bound( 0, 0, pImage->GetWidth(), pImage->GetHeight() );
Gdiplus::BitmapData lockedBitmapData;
int bpp = pImage->GetBPP();
int imageRowSize = pImage->GetWidth() * (bpp/8);


if ( bpp == 24 )
{
image->LockBits( &bound, Gdiplus::ImageLockModeWrite, PixelFormat24bppRGB, &lockedBitmapData );
}
else if ( bpp == 32 )
{
image->LockBits( &bound, Gdiplus::ImageLockModeWrite, PixelFormat32bppARGB, &lockedBitmapData );
}
else
{
// we shouldn't be getting here
AfxDebugBreak();
return NULL;
}


BYTE* pSrcPointer = (BYTE*)pImage->GetBits();
BYTE* pDstPointer = (BYTE*)lockedBitmapData.Scan0;


for ( int i=0; iGetHeight(); i++ )
{
memcpy( pDstPointer, pSrcPointer, imageRowSize );
pSrcPointer += pImage->GetPitch();
pDstPointer += lockedBitmapData.Stride;
}


image->UnlockBits( &lockedBitmapData );
return image;
}

你可能感兴趣的:(CImage转换Gdiplus::Bitmap)