gdi+ example ?
-
how does one do this in gdi+, mfc - load png image into memory - access array of values, eg as int or rgb bytes and apply any changes to image, if this step is needed - rotate image - crop image - save as bmp i currently used CxImage, but it seems buggy - totally weird things happen after i use ::Rotate :(( Thank You
-
how does one do this in gdi+, mfc - load png image into memory - access array of values, eg as int or rgb bytes and apply any changes to image, if this step is needed - rotate image - crop image - save as bmp i currently used CxImage, but it seems buggy - totally weird things happen after i use ::Rotate :(( Thank You
Bitmap class constructors will load a png image (as well as Bitmap::FromFile()) Image::RotateFlip() will rotate and/or flip To crop, extract the desired portion from the source image into a second image (see below). There's a Graphics::DrawImage() overload that will do just that. Bitmap::Save() will save as any of the supported types (see below). This sample code should be enough to get you started...
// Resize png to 320x240 bmp
// The GDI+ Bitmap class is derived from the GDI+ Image class
// I've made no assumptions on the src image dimensions
// You should use Image::GetHeight()/Image::GetWidth() in real life :)Gdiplus::Bitmap SrcBitmap(L"C:\\test.png", FALSE);
Gdiplus::Bitmap DstBitmap(320, 240, SrcBitmap.GetPixelFormat());
Graphics DstGraphics(&DstBitmap);
DstGraphics.DrawImage(&SrcBitmap, 0, 0, 320, 240);CLSID bmpClsid;
GetEncoderClsid(L"image/bmp", &bmpClsid);DstBitmap.Save(L"C:\\test.bmp", &bmpClsid, NULL);
// This utility ripped right from the SDK
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytesImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // FailurepImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // FailureGetImageEncoders(num, size, pImageCodecInfo);
for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j; // Success
}
}free(pImageCodecInfo);
return -1; // Failure
}-- modified at 14:14 Sunday 21st January, 2007
edited for splelling
-
how does one do this in gdi+, mfc - load png image into memory - access array of values, eg as int or rgb bytes and apply any changes to image, if this step is needed - rotate image - crop image - save as bmp i currently used CxImage, but it seems buggy - totally weird things happen after i use ::Rotate :(( Thank You
Forgot one... You can use Bitmap::LockBits()/Bitmap::UnlockBits() to access the image bits. Mark
-
how does one do this in gdi+, mfc - load png image into memory - access array of values, eg as int or rgb bytes and apply any changes to image, if this step is needed - rotate image - crop image - save as bmp i currently used CxImage, but it seems buggy - totally weird things happen after i use ::Rotate :(( Thank You
You can use of GDI+ about this subjects but if you want to load and change some things on the image and save it you can use also of
CImage
class but for rotate GDI+ is better however its possible with CImage but GDI+ is easy.
WhiteSky