Skip to content

Instantly share code, notes, and snippets.

@fileformat-heic-gists
fileformat-heic-gists / heic-to-png.cs
Last active July 29, 2024 10:43
Convert HEIC to PNG programatically using System.Windows.Media.Imaging.WriteableBitmap
// Open the HEIC file named "filename.heic" in read mode using FileStream.
using (var fs = new FileStream("filename.heic", FileMode.Open))
{
// Load the HEIC image from the file stream into a HeicImage object.
HeicImage image = HeicImage.Load(fs);
// Extract the pixel data from the HEIC image in the BGRA32 format, storing it in a byte array.
var pixels = image.GetByteArray(Heic.Decoder.PixelFormat.Bgra32);
// Retrieve the width and height of the HEIC image.
var width = (int)image.Width;