public static Image ResizeBitmap(Image sourceBMP, int width, int height) { ResamplingService resamplingService = new ResamplingService(); resamplingService.Filter = ResamplingFilters.Box; ushort[][,] input = ConvertBitmapToArray((Bitmap)sourceBMP); ushort[][,] output = resamplingService.Resample(input, width, height); Image imgCustom = (Image)ConvertArrayToBitmap(output); return imgCustom; }
public MainForm() { // // load and show original image // Image imgInput = Image.FromFile(FILE_INPUT); Image imgCheckerboard = Image.FromFile(FILE_CHECKERBOARD); PictureBox pb1 = new PictureBox(); pb1.BackgroundImage = imgCheckerboard; pb1.Image = imgInput; pb1.Location = new Point(0, 0); pb1.Parent = this; pb1.Size = imgInput.Size; // // new image size // Size nSize = new Size(imgInput.Width * 4, imgInput.Height * 4); // // resample using GDI+ // Image imgGdi = new Bitmap(nSize.Width, nSize.Height); Graphics grfx = Graphics.FromImage(imgGdi); grfx.InterpolationMode = InterpolationMode.HighQualityBicubic; // necessary setting for proper work with image borders grfx.PixelOffsetMode = PixelOffsetMode.HighQuality; grfx.DrawImage(imgInput, new Rectangle(new Point(0, 0), nSize), new Rectangle(new Point(0, 0), imgInput.Size), GraphicsUnit.Pixel); grfx.Dispose(); PictureBox pb2 = new PictureBox(); pb2.BackgroundImage = imgCheckerboard; pb2.Image = imgGdi; pb2.Location = new Point(imgInput.Width + SPACING, 0); pb2.Parent = this; pb2.Size = imgGdi.Size; // // resample using ResamplingService // ResamplingService resamplingService = new ResamplingService(); resamplingService.Filter = ResamplingFilters.CubicBSpline; ushort[][,] input = ConvertBitmapToArray((Bitmap)imgInput); ushort[][,] output = resamplingService.Resample(input, nSize.Width, nSize.Height); Image imgCustom = (Image)ConvertArrayToBitmap(output); PictureBox pb3 = new PictureBox(); pb3.BackgroundImage = imgCheckerboard; pb3.Image = imgCustom; pb3.Location = new Point(imgInput.Width + SPACING + imgGdi.Width + SPACING, 0); pb3.Parent = this; pb3.Size = nSize; // // set main form properties // this.ClientSize = new Size( pb1.Width + SPACING + pb2.Width + SPACING + pb3.Width, Math.Max(pb1.Height, pb2.Height)); this.Text = "Resampling Test"; }