Skip to content

Instantly share code, notes, and snippets.

@fileformat-heic-gists
fileformat-heic-gists / heic-to-argb32-pixels.cs
Last active July 24, 2024 23:32
Read HEIC file into int array with Argb32 data
// Open the HEIC file named "filename.heic" 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 pixel data from the HEIC image in the ARGB32 format and store it in an integer array.
int[] pixels = image.GetInt32Array(Heic.Decoder.PixelFormat.Argb32);
}
@fileformat-heic-gists
fileformat-heic-gists / heic-to-png-using-bitmap.cs
Created July 29, 2024 05:08
Convert HEIC to PNG programatically using System.Drawing.Common.Bitmap
// 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 ARGB32 format, storing it in an int array.
var pixels = image.GetInt32Array(Heic.Decoder.PixelFormat.Argb32);
// Retrieve the width and height of the HEIC image.
var width = (int)image.Width;
@fileformat-heic-gists
fileformat-heic-gists / heic-collection-to-png.cs
Last active July 29, 2024 10:41
Convert HEIC collection to a set of PNG files programatically
// 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);
// For each frame of the image do the following:
foreach (var key in image.Frames.Keys)
{
// Retrieve the width and height of the HEIC image.
@fileformat-heic-gists
fileformat-heic-gists / heic-to-jpg.cs
Last active July 29, 2024 10:41
Convert HEIC to JPG 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;
@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;