Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API Proposal]: System.Drawing.Imaging.ImageFormat.Heif and Webp. #70422

Closed
teo-tsirpanis opened this issue Jun 8, 2022 · 5 comments · Fixed by #71227
Closed

[API Proposal]: System.Drawing.Imaging.ImageFormat.Heif and Webp. #70422

teo-tsirpanis opened this issue Jun 8, 2022 · 5 comments · Fixed by #71227
Assignees
Labels
api-approved API was approved in API review, it can be implemented area-System.Drawing
Milestone

Comments

@teo-tsirpanis
Copy link
Contributor

teo-tsirpanis commented Jun 8, 2022

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

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; }
}

API Usage

// Fancy the value
Bitmap bmp = new Bitmap(184, 475);
// ...
bmp.Save("myimage.heif", ImageFormat.Heif);
bmp.Save("myimage.webp", ImageFormap.Webp);

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

Footnotes

  1. Source: I bisected Windows 10 SDK versions and checked the contents of gdiplusimaging.h.

@teo-tsirpanis teo-tsirpanis added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Jun 8, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jun 8, 2022
@ghost
Copy link

ghost commented Jun 8, 2022

Tagging subscribers to this area: @dotnet/area-system-drawing
See info in area-owners.md if you want to be subscribed.

Issue Details

Background and motivation

GDI+ seems to support the newer HEIF and WebP image formats. We should expose this functionality to System.Drawing.Common.

API Proposal

namespace System.Drawing.Common;

public class ImageFormat {
    // I need to find in which version of Windows they were introduced.
    [SupportedOSPlatform("winTBD")]
    public static ImageFormat Heif { get; }
    [SupportedOSPlatform("winTBD")]
    public static ImageFormat Webp { get; }
}

API Usage

// Fancy the value
Bitmap bmp = new Bitmap(184, 475);
// ...
bmp.Save("myimage.heif", ImageFormat.Heif);
bmp.Save("myimage.webp", ImageFormap.Webp);

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

Author: teo-tsirpanis
Assignees: -
Labels:

api-suggestion, area-System.Drawing

Milestone: -

@teo-tsirpanis teo-tsirpanis self-assigned this Jun 8, 2022
@teo-tsirpanis teo-tsirpanis changed the title [API Proposal]: System.Drawing.Common.ImageFormat.Heif and Webp. [API Proposal]: System.Drawing.Imaging.ImageFormat.Heif and Webp. Jun 8, 2022
@danmoseley danmoseley added api-ready-for-review API is ready for review, it is NOT ready for implementation and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Jun 9, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jun 9, 2022
@danmoseley danmoseley added this to the 7.0.0 milestone Jun 9, 2022
@danmoseley
Copy link
Member

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.

@saucecontrol
Copy link
Member

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.

@saucecontrol
Copy link
Member

saucecontrol commented Jun 23, 2022

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));
}

@terrajobst terrajobst added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for review, it is NOT ready for implementation labels Jun 23, 2022
@terrajobst
Copy link
Member

terrajobst commented Jun 23, 2022

Video

  • Looks good as proposed
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; }
}

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jun 23, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jun 29, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jul 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved API was approved in API review, it can be implemented area-System.Drawing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants