void Sprite::SetImage( const CImage* pImage )
{
	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;
	}

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

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

	image->UnlockBits( &lockedBitmapData );

	SetImage( image, true );
}

출처:http://forums.devshed.com/c-programming-42/converting-cimage-to-gdiplus-image-351742.html

Posted by pkss
,