Skip to content

Instantly share code, notes, and snippets.

@openize-imaging-gists
Last active June 3, 2024 15:20
Show Gist options
  • Save openize-imaging-gists/be2b3fe9bfad3eab36d60141e3374d68 to your computer and use it in GitHub Desktop.
Save openize-imaging-gists/be2b3fe9bfad3eab36d60141e3374d68 to your computer and use it in GitHub Desktop.
Openize.HEIC Code Snippets
// Decode .heic file to int array with Argb32 data
using (var fs = new FileStream("filename.heic", FileMode.Open))
{
HeicImage image = HeicImage.Load(fs);
int[] pixels = image.GetInt32Array(Heic.Decoder.PixelFormat.Argb32);
}
using (var fs = new FileStream("filename.heic", FileMode.Open))
{
HeicImage image = HeicImage.Load(fs);
var pixels = image.GetByteArray(Heic.Decoder.PixelFormat.Bgra32);
var width = (int)image.Width;
var height = (int)image.Height;
var wbitmap = new WriteableBitmap(width, height, 72, 72, PixelFormats.Bgra32, null);
var rect = new Int32Rect(0, 0, width, height);
wbitmap.WritePixels(rect, pixels, 4 * width, 0);
using (FileStream saveStream = new FileStream("output.jpg", FileMode.OpenOrCreate))
{
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(wbitmap));
encoder.Save(saveStream);
}
}
using (var fs = new FileStream("filename.heic", FileMode.Open))
{
HeicImage image = HeicImage.Load(fs);
var pixels = image.GetByteArray(Heic.Decoder.PixelFormat.Bgra32);
var width = (int)image.Width;
var height = (int)image.Height;
var wbitmap = new WriteableBitmap(width, height, 72, 72, PixelFormats.Bgra32, null);
var rect = new Int32Rect(0, 0, width, height);
wbitmap.WritePixels(rect, pixels, 4 * width, 0);
using (FileStream saveStream = new FileStream("output.png", FileMode.OpenOrCreate))
{
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(wbitmap));
encoder.Save(saveStream);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment