Hello i'm trying to change scale GDIplus::Bitmap and save in memory scaled BItmap, and i have problem. I try many different sample, and my result is NULL. For Example I try change resolution for image, using SetResolution, also i try convert bitmap from image->graphic and use one of constructors GDIplus::Bitmap scale, but i haven't result. For example i try next code:
Bitmap *bitmap = new Bitmap((int32)width, (int32)height,PixelFormat32bppARGB);
bitmap=bmp.Clone(0,0,W,H,PixelFormat32bppPARGB);
mBitmap=(void *)bitmap->Clone(0.0f,0.0f,width,height,PixelFormat32bppPARGB);
Compute the new width and height (if you have the scaling factors)
float newWidth = horizontalScalingFactor * (float) originalBitmap->GetWidth();
float newHeight = verticalScalingFactor * (float) originalBitmap->GetHeight();
or the scaling factors if the new dimensions are known
float horizontalScalingFactor = (float) newWidth / (float) originalBitmap->GetWidth();
float verticalScalingFactor = (float) newHeight / (float) originalBitmap->GetHeight();
Create a new empty bitmap with sufficient space for the scaled image
Image* img = new Bitmap((int) newWidth, (int) newHeight);
Create a new Graphics to draw on the created bitmap:
Graphics g(img);
Apply a scale transform to the Graphics and draw the image
g.ScaleTransform(horizontalScalingFactor, verticalScalingFactor);
g.DrawImage(originalBitmap, 0, 0);
img
is now another Bitmap with a scaled version of the original image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With