Scaling performance problem

  • Thread starter Thread starter James Dean
  • Start date Start date
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);
}
 
Hi James,

From my point-of-view, you've got to choose:

A) QUALITY (InterpolationMode.HighQualityBicubic)
B) SPEED (InterpolationMode.NearestNeighbor)

....and from my practise i can say that speed difference
can be greater than 8x (depends on image size)

Regards

Marcin
 
Back
Top