Last active
June 3, 2024 15:20
-
-
Save openize-imaging-gists/be2b3fe9bfad3eab36d60141e3374d68 to your computer and use it in GitHub Desktop.
Openize.HEIC Code Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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