public swmi.BitmapFrame Get(swmi.BitmapSource image, float scale, int width, int height, swm.BitmapScalingMode scalingMode) { if (width <= 0 || height <= 0 || scale <= 0) { return(null); } var _cachedFrame = _cachedFrameReference?.Target as swmi.BitmapFrame; // if parameters are the same, return cached bitmap if (_cachedFrame != null && scale == _scale && width == _width && height == _height && scalingMode == _scalingMode) { return(_cachedFrame); } // generate a new bitmap with the desired size & scale. var scaledwidth = (int)Math.Round(width * scale); var scaledheight = (int)Math.Round(height * scale); if (scaledwidth <= 0 || scaledheight <= 0) { return(null); } var group = new swm.DrawingGroup(); swm.RenderOptions.SetBitmapScalingMode(group, scalingMode); group.Children.Add(new swm.ImageDrawing(image, new sw.Rect(0, 0, width, height))); var targetVisual = new swm.DrawingVisual(); using (var targetContext = targetVisual.RenderOpen()) targetContext.DrawDrawing(group); // note, this uses a GDI handle, which are limited (only 5000 or so can be created). // There's no way to get around it other than just not creating that many and using GC.Collect/WaitForPendingFinalizers. // we can't do it in Eto as it'd be a serious performance hit. var target = new swmi.RenderTargetBitmap(scaledwidth, scaledheight, 96 * scale, 96 * scale, swm.PixelFormats.Default); target.Render(targetVisual); target.Freeze(); _cachedFrame = swmi.BitmapFrame.Create(target); _cachedFrame.Freeze(); _scale = scale; _width = width; _height = height; _scalingMode = scalingMode; _cachedFrameReference = new WeakReference(_cachedFrame); return(_cachedFrame); }
/// <summary> /// Resizes a bitmap frame /// </summary> /// <param name="photo"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="scalingMode"></param> /// <returns></returns> public static BitmapFrame Resize(BitmapFrame photo, int width, int height, System.Windows.Media.BitmapScalingMode scalingMode) { var group = new System.Windows.Media.DrawingGroup(); System.Windows.Media.RenderOptions.SetBitmapScalingMode(group, scalingMode); group.Children.Add(new System.Windows.Media.ImageDrawing(photo, new System.Windows.Rect(0, 0, width, height))); var targetVisual = new System.Windows.Media.DrawingVisual(); var targetContext = targetVisual.RenderOpen(); targetContext.DrawDrawing(group); var target = new RenderTargetBitmap(width, height, 96, 96, System.Windows.Media.PixelFormats.Default); targetContext.Close(); target.Render(targetVisual); var targetFrame = BitmapFrame.Create(target); return(targetFrame); }
public static ImageInterpolation ToEto(this swm.BitmapScalingMode value) { switch (value) { case swm.BitmapScalingMode.HighQuality: return(ImageInterpolation.High); case swm.BitmapScalingMode.LowQuality: return(ImageInterpolation.Low); case swm.BitmapScalingMode.NearestNeighbor: return(ImageInterpolation.None); case swm.BitmapScalingMode.Unspecified: return(ImageInterpolation.Default); default: throw new NotSupportedException(); } }
static swmi.BitmapFrame Resize(swmi.BitmapSource image, float scale, int width, int height, swm.BitmapScalingMode scalingMode) { var group = new swm.DrawingGroup(); swm.RenderOptions.SetBitmapScalingMode(group, scalingMode); group.Children.Add(new swm.ImageDrawing(image, new sw.Rect(0, 0, width, height))); var targetVisual = new swm.DrawingVisual(); var targetContext = targetVisual.RenderOpen(); targetContext.DrawDrawing(group); width = (int)Math.Round(width * scale); height = (int)Math.Round(height * scale); var target = new swmi.RenderTargetBitmap(width, height, 96 * scale, 96 * scale, swm.PixelFormats.Default); targetContext.Close(); target.Render(targetVisual); return(swmi.BitmapFrame.Create(target)); }
public Column() { ScalingMode = swm.BitmapScalingMode.HighQuality; }