protected virtual bool IsSameSrcImage(ImageResizeUtil other) { if (other != null) { return(File == other.File && Image == other.Image); } return(false); }
/// <summary> /// Check whether the required destination image properties have /// changed /// </summary> /// <param name="other"></param> /// <returns></returns> protected virtual bool IsSameDstImage(ImageResizeUtil other) { if (other != null) { return(Width == other.Width && Height == other.Height && UsePercentages == other.UsePercentages && PreserveAspectRatio == other.PreserveAspectRatio); } return(false); }
public virtual Image GetThumbnail() { // Flag whether a new image is required bool recalculate = false; recalculate = IsInCache(recalculate); double new_width = Width; double new_height = Height; if (!IsSameDstImage(_cache)) { CalucateWidthAndHeight(ref new_height, ref new_width); recalculate = true; } if (recalculate) { // Calculate the new image if (_dstImage != null) { _dstImage.Dispose(); _graphics.Dispose(); } Bitmap bitmap = new Bitmap((int)new_width, (int)new_height, _srcImage.PixelFormat); _graphics = Graphics.FromImage(bitmap); _graphics.SmoothingMode = SmoothingMode.HighQuality; _graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; _graphics.DrawImage(_srcImage, 0, 0, bitmap.Width, bitmap.Height); _dstImage = bitmap; // Cache the image and its associated settings _cache = MemberwiseClone() as ImageResizeUtil; } return(_dstImage); }