/// <summary> /// Resize an image. /// </summary> /// <param name="img">Image to resize.</param> /// <param name="w">Width of the returned image.</param> /// <param name="h">Height of the returned image.</param> /// <param name="f">Flags to customize scaling behavior.</param> /// <returns>Resized image. This object is always different /// from <paramref name="img" /> (i.e. they can be /// disposed separately).</returns> public static Image ScaleImage(Image img, int w, int h, ScaleTransformFlags f) { if (img == null) { throw new ArgumentNullException("img"); } if (w < 0) { throw new ArgumentOutOfRangeException("w"); } if (h < 0) { throw new ArgumentOutOfRangeException("h"); } bool bUIIcon = ((f & ScaleTransformFlags.UIIcon) != ScaleTransformFlags.None); // We must return a Bitmap object for UIUtil.CreateScaledImage Bitmap bmp = new Bitmap(w, h, PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(bmp)) { g.Clear(Color.Transparent); g.SmoothingMode = SmoothingMode.HighQuality; g.CompositingQuality = CompositingQuality.HighQuality; int wSrc = img.Width; int hSrc = img.Height; InterpolationMode im = InterpolationMode.HighQualityBicubic; if ((wSrc > 0) && (hSrc > 0)) { if (bUIIcon && ((w % wSrc) == 0) && ((h % hSrc) == 0)) { im = InterpolationMode.NearestNeighbor; } // else if((w < wSrc) && (h < hSrc)) // im = InterpolationMode.HighQualityBilinear; } else { Debug.Assert(false); } g.InterpolationMode = im; RectangleF rSource = new RectangleF(0.0f, 0.0f, wSrc, hSrc); RectangleF rDest = new RectangleF(0.0f, 0.0f, w, h); AdjustScaleRects(ref rSource, ref rDest); g.DrawImage(img, rDest, rSource, GraphicsUnit.Pixel); } return(bmp); }
/// <summary> /// Resize an image. /// </summary> /// <param name="img">Image to resize.</param> /// <param name="w">Width of the returned image.</param> /// <param name="h">Height of the returned image.</param> /// <param name="f">Flags to customize scaling behavior.</param> /// <returns>Resized image. This object is always different /// from <paramref name="img" /> (i.e. they can be /// disposed separately).</returns> public static Image ScaleImage(Image img, int w, int h, ScaleTransformFlags f) { if(img == null) throw new ArgumentNullException("img"); if(w < 0) throw new ArgumentOutOfRangeException("w"); if(h < 0) throw new ArgumentOutOfRangeException("h"); bool bUIIcon = ((f & ScaleTransformFlags.UIIcon) != ScaleTransformFlags.None); // We must return a Bitmap object for UIUtil.CreateScaledImage Bitmap bmp = new Bitmap(w, h, PixelFormat.Format32bppArgb); using(Graphics g = Graphics.FromImage(bmp)) { g.Clear(Color.Transparent); g.SmoothingMode = SmoothingMode.HighQuality; g.CompositingQuality = CompositingQuality.HighQuality; int wSrc = img.Width; int hSrc = img.Height; InterpolationMode im = InterpolationMode.HighQualityBicubic; if((wSrc > 0) && (hSrc > 0)) { if(bUIIcon && ((w % wSrc) == 0) && ((h % hSrc) == 0)) im = InterpolationMode.NearestNeighbor; // else if((w < wSrc) && (h < hSrc)) // im = InterpolationMode.HighQualityBilinear; } else { Debug.Assert(false); } g.InterpolationMode = im; RectangleF rSource = new RectangleF(0.0f, 0.0f, wSrc, hSrc); RectangleF rDest = new RectangleF(0.0f, 0.0f, w, h); AdjustScaleRects(ref rSource, ref rDest); g.DrawImage(img, rDest, rSource, GraphicsUnit.Pixel); } return bmp; }
public static Image ScaleImage(Image m_imgOrg, int?w, int?h, ScaleTransformFlags flags) { return(null); }
public static Image <Rgba32> ScaleImage(Image <Rgba32> m_imgOrg, int?w, int?h, ScaleTransformFlags flags) { m_imgOrg.Mutate(i => i.Resize(w.GetValueOrDefault(), h.GetValueOrDefault())); return(m_imgOrg); }