J
James Dean
I have tried a few different methods for scaling an image down but all
seem a bit on the slow side. Is there any way i can make this scaling
faster.......
Here is how i do it now.
To display my image at 1:2 zoom i have the following
xScaleFactor = 0.5
yScaleFactor = 0.5
public static Bitmap ScaleBitmap(Bitmap inputBmp, double xScaleFactor,
double yScaleFactor) {
//Create a new bitmap object based on the input
Bitmap newBmp = new Bitmap((int)(inputBmp.Size.Width*xScaleFactor),
(int)(inputBmp.Size.Height*yScaleFactor),
PixelFormat.Format32bppArgb);//Graphics.FromImage doesn't
like Indexed pixel format
//Create a graphics object attached to the new bitmap
Graphics newBmpGraphics = Graphics.FromImage(newBmp);
newBmpGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
newBmpGraphics.ScaleTransform((float)xScaleFactor, (float)yScaleFactor);
Rectangle drawRect = new Rectangle(0, 0, inputBmp.Size.Width,
inputBmp.Size.Height);
newBmpGraphics.DrawImage(inputBmp, drawRect, drawRect,
GraphicsUnit.Pixel);
newBmpGraphics.Dispose();
return ConvertBitmap(newBmp, inputBmp.RawFormat);
}
seem a bit on the slow side. Is there any way i can make this scaling
faster.......
Here is how i do it now.
To display my image at 1:2 zoom i have the following
xScaleFactor = 0.5
yScaleFactor = 0.5
public static Bitmap ScaleBitmap(Bitmap inputBmp, double xScaleFactor,
double yScaleFactor) {
//Create a new bitmap object based on the input
Bitmap newBmp = new Bitmap((int)(inputBmp.Size.Width*xScaleFactor),
(int)(inputBmp.Size.Height*yScaleFactor),
PixelFormat.Format32bppArgb);//Graphics.FromImage doesn't
like Indexed pixel format
//Create a graphics object attached to the new bitmap
Graphics newBmpGraphics = Graphics.FromImage(newBmp);
newBmpGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
newBmpGraphics.ScaleTransform((float)xScaleFactor, (float)yScaleFactor);
Rectangle drawRect = new Rectangle(0, 0, inputBmp.Size.Width,
inputBmp.Size.Height);
newBmpGraphics.DrawImage(inputBmp, drawRect, drawRect,
GraphicsUnit.Pixel);
newBmpGraphics.Dispose();
return ConvertBitmap(newBmp, inputBmp.RawFormat);
}