iron-software / IronSoftware.System.Drawing

An open-source System.Drawing.Common replacement for .NET 5 and above on all platforms. Bringing together System.Drawing, Maui, and ImageSharp's Bitmap, Image, Font, and Shape types via an agnostic free NuGet package.
Other
114 stars 18 forks source link

DW-23: Fixing System.OutOfMemoryException in x86 #104

Closed mee-ironsoftware closed 5 months ago

mee-ironsoftware commented 5 months ago

Description

The root cause of the issue lies in the ExportBytes() function when attempting to return a large byte array containing a giant image (4958x7016 pixels). This high resolution consumes significant memory, leading to an OutOfMemoryException.

Fixing only SaveAs() function by change to use FileStream instead of byte[].

Doesn't have a good solution for ExportBytes() because we export a byte array out. To solve this issue on x86 please change to use ExportStream() instead.

Fixes #DW-23

Type of change

Please select the relevant option by placing an 'x' inside the brackets, like this: [x].

How Has This Been Tested?

Test locally using x86 and add x86 tests on DevOps (.NET472, .NET60, and .NET70)

Checklist:

Please run through the checklist as much as possible and mark the items completed by placing an 'x' inside the brackets, like this: [x].