Skip to content

Commit

Permalink
Merge pull request #2552 from cwensley/curtis/wpf-fix-gdi-handles-issue
Browse files Browse the repository at this point in the history
Wpf: Fix GDI handle issues when using resized Bitmaps
  • Loading branch information
cwensley authored Sep 11, 2023
2 parents 51b55dc + 4e3070e commit 9826d7c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Eto.Wpf/Drawing/BitmapHandler.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,14 @@ public void Create(Image image, int width, int height, ImageInterpolation interp
drawingContext.DrawDrawing(group);

var resizedImage = new swmi.RenderTargetBitmap(width, height, source.DpiX, source.DpiY, swm.PixelFormats.Default);
resizedImage.RenderWithCollect(drawingVisual);
Control = resizedImage;
resizedImage.Render(drawingVisual);

// Don't use RenderTargetBitmap directly, it can run out of GDI handles when you have many bitmaps.
var writable = new swmi.WriteableBitmap(resizedImage);
Control = writable;

// collect immediately to get rid of the handle use
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, false);
}

protected override void Initialize()
Expand Down

0 comments on commit 9826d7c

Please sign in to comment.