Closed teo-tsirpanis closed 2 years ago
Tagging subscribers to this area: @dotnet/area-system-drawing See info in area-owners.md if you want to be subscribed.
Author: | teo-tsirpanis |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `area-System.Drawing` |
Milestone: | - |
Aside from these two, we match the GDI+ list. Although we're generally adding not features to this library, its goal is to expose GDI+, we do want to enable these new formats, and in this case it's simply a matter of passing through different constants.
It's more than a matter of missing constants. System.Drawing currently throws OutOfMemoryException
when attempting to load either WebP or HEIC images. AFAIK, GDI+ should be using the WIC codecs underneath, but even with these codecs present and working from WIC code, they don't work from System.Drawing.
Also, WIC has both decoder and encoder for HEIC/HEIF (although they don't work without the HEVC Video Extensions installed from Microsoft Store), but it only has a decoder for WebP. The above example to save as WebP wouldn't work even if everything were wired up correctly.
Just tested Image.Save
with the added GUIDs. It appears to work (no exception thrown), but the output in both cases is actually PNG.
static void TestFormats()
{
Guid ImageFormatHEIF = new(0xb96b3cb6, 0x0728, 0x11d3, 0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e);
Guid ImageFormatWEBP = new(0xb96b3cb7, 0x0728, 0x11d3, 0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e);
using var img = new Bitmap(256, 256);
img.Save("test.webp", new ImageFormat(ImageFormatWEBP));
img.Save("test.heif", new ImageFormat(ImageFormatHEIF));
}
namespace System.Drawing.Imaging;
public class ImageFormat
{
[SupportedOSPlatform("windows10.0.17763.0")]
public static ImageFormat Heif { get; }
[SupportedOSPlatform("windows10.0.17763.0")]
public static ImageFormat Webp { get; }
}
Background and motivation
GDI+ seems to support the newer HEIF and WebP image formats since Windows 10 1809 [^1]. We should expose this functionality to
System.Drawing.Common
.API Proposal
API Usage
Alternative Designs
Users can use these formats by creating an
ImageFormat
object with the format's GUID but it is not easily found in the documentation.Risks
No response
[^1]: Source: I bisected Windows 10 SDK versions and checked the contents of
gdiplusimaging.h
.