From 4a60587fe3fa51a4ace937d134ea53dbe1c7db11 Mon Sep 17 00:00:00 2001 From: Curtis Wensley Date: Thu, 14 Sep 2023 13:25:25 -0700 Subject: [PATCH] Wpf: Don't store RenderTargetBitmap anywhere --- src/Eto.Wpf/Drawing/BitmapHandler.cs | 2 ++ src/Eto.Wpf/Drawing/CachedBitmapFrame.cs | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) mode change 100644 => 100755 src/Eto.Wpf/Drawing/CachedBitmapFrame.cs diff --git a/src/Eto.Wpf/Drawing/BitmapHandler.cs b/src/Eto.Wpf/Drawing/BitmapHandler.cs index c7b94e4f9..76ba530ac 100755 --- a/src/Eto.Wpf/Drawing/BitmapHandler.cs +++ b/src/Eto.Wpf/Drawing/BitmapHandler.cs @@ -137,6 +137,8 @@ protected override void Initialize() public void SetBitmap(swmi.BitmapSource bitmap) { + if (bitmap is swmi.RenderTargetBitmap) + bitmap = new swmi.WriteableBitmap(bitmap); Control = bitmap; SetFrozen(); } diff --git a/src/Eto.Wpf/Drawing/CachedBitmapFrame.cs b/src/Eto.Wpf/Drawing/CachedBitmapFrame.cs old mode 100644 new mode 100755 index 828886d71..3ef98d94b --- a/src/Eto.Wpf/Drawing/CachedBitmapFrame.cs +++ b/src/Eto.Wpf/Drawing/CachedBitmapFrame.cs @@ -38,10 +38,11 @@ public swmi.BitmapFrame Get(swmi.BitmapSource image, float scale, int width, int // 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(); + target.RenderWithCollect(targetVisual); + + var writable = new swmi.WriteableBitmap(target); - _cachedFrame = swmi.BitmapFrame.Create(target); + _cachedFrame = swmi.BitmapFrame.Create(writable); _cachedFrame.Freeze(); _scale = scale; _width = width;