FileFormat.HEIC for .NET
Simplify Process of Reading and Converting HEIC Images Using .NET API
Effortlessly edit images with FileFormat.HEIC, a lightweight open-source .NET API, streamlining HEIC files convertion and automation
FileFormat.HEIC for .NET revolutionizes your HEIC image processing experience. In this comprehensive guide, we delve into the functionalities and benefits of leveraging FileFormat.HEIC, a lightweight open-source .NET API, to effortlessly handle HEIC files with ease.
HEIC, short for High Efficiency Image File Format with HEVC (High Efficiency Video Coding) encoded images, is a modern image format developed to replace JPEG as the default image format on iOS devices. While HEIC offers superior image quality and compression, its compatibility across platforms remains a challenge. Many applications and platforms lack native support for HEIC, making it difficult to view or edit these files without conversion.
FileFormat.HEIC emerges as a powerful solution for seamlessly converting HEIC files to various formats, including JPG, PNG, PDF and more. This lightweight open-source .NET API simplifies HEIC image operations, offering developers and users a user-friendly interface to handle HEIC files effortlessly.
FileFormat.HEIC is available under Openize License.
Key Features and Benefits- Effortless Conversion: Convert HEIC files to popular formats such as JPG and PNG with a few lines of code.
- HEVC Decoder Integration: Utilize the built-in HEVC decoder to decode HEIC files, ensuring accurate and reliable conversion.
- Extensive Format Support: Convert HEIC files to a wide range of formats, including PDF and WEBP, enabling versatile usage across different platforms and applications.
- Open Source and Free: Enjoy the benefits of an open-source solution with no licensing fees, making it accessible to developers and users of all levels.
- Seamless Integration with C# Applications: Integrate FileFormat.HEIC effortlessly into your C# applications, enabling seamless HEIC file handling within your existing workflows.
- Effortless Conversion: Convert HEIC files to popular formats such as JPG and PNG with a few lines of code.
- HEVC Decoder Integration: Utilize the built-in HEVC decoder to decode HEIC files, ensuring accurate and reliable conversion.
- Extensive Format Support: Convert HEIC files to a wide range of formats, including PDF and WEBP, enabling versatile usage across different platforms and applications.
- Open Source and Free: Enjoy the benefits of an open-source solution with no licensing fees, making it accessible to developers and users of all levels.
- Seamless Integration with C# Applications: Integrate FileFormat.HEIC effortlessly into your C# applications, enabling seamless HEIC file handling within your existing workflows.
How to Get Started with FileFormat.HEIC for .NET
Getting started with FileFormat.HEIC is quick and easy. Simply follow these steps:
- Install FileFormat.HEIC: Install the FileFormat.HEIC package via NuGet Package Manager or .NET CLI.
- Integrate with Your Project: Reference the FileFormat.HEIC library in your C# project.
- Start Converting: Utilize the simple API provided by FileFormat.HEIC to convert HEIC files to your desired format.
The recommended way to install FileFormat.HEIC for .NET is using NuGet. Please use the following command for a smooth installation.
Install FileFormat.HEIC for .NET via NuGet
NuGet> Install-Package FileFormat.HEIC
You can also download it directly from GitHub.Read HEIC File into Array in C#
This code snippet efficiently loads a HEIC image file, extracts its pixel data in the specified format, and stores it in an array for subsequent operations.
- Open the HEIC file named "filename.heic" using
FileStream
. - Load the HEIC image from the file stream into a
HeicImage
object. - Extract pixel data from the HEIC image in the ARGB32 format and store it in an integer array.
Copy and paste the code snippet below into your main file and execute the program.
Read .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);
}
Read HEIC file into WriteableBitmap in C#
The following code illustrates how to open an existing HEIC image file, extract its pixel data, and create a WriteableBitmap object for further processing:
- Open the HEIC file named "filename.heic" using
FileStream
. - Load the HEIC image from the file stream into a
HeicImage
object. - Extract pixel data from the HEIC image in the BGRA32 format and store it in an array.
- Get the width and height of the HEIC image.
- Create a
WriteableBitmap
object with the specified width, height, and pixel format. - Define a rectangle covering the entire bitmap area.
- Write the extracted pixel data to the
WriteableBitmap
object.
Copy and paste the code snippet below into your main file and execute the program.
Read .heic file to System.Windows.Media.Imaging.WriteableBitmap
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;
WriteableBitmap wbitmap = new WriteableBitmap(width, height, 72, 72, PixelFormats.Bgra32, null);
Int32Rect rect = new Int32Rect(0, 0, width, height);
wbitmap.WritePixels(rect, pixels, 4 * width, 0);
}
Read HEIC file into Bitmap in C#
The following code illustrates how to open an existing HEIC image file, extract its pixel data, and create a Bitmap object for further processing:
- Open the HEIC file named "filename.heic" using
FileStream
. - Load the HEIC image from the file stream into a
HeicImage
object. - Extract the pixel data from the HEIC image in the ARGB32 format, storing it in an int array.
- Get the width and height of the HEIC image.
- Create a
Bitmap
object with the specified width, and height. - Set pixel data for each pixel of the
Bitmap
.
Copy and paste the code snippet below into your main file and execute the program.
Read .heic file to System.Drawing.Common.Bitmap
using (var fs = new FileStream("filename.heic", FileMode.Open))
{
HeicImage image = HeicImage.Load(fs);
var pixels = image.GetInt32Array(Heic.Decoder.PixelFormat.Argb32);
var width = (int)image.Width;
var height = (int)image.Height;
var i = 0;
Bitmap myBitmap = new Bitmap(width, height);
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
myBitmap.SetPixel(x, y, Color.FromArgb(pixels[i++]));
}
Convert HEIC to JPG Programatically in C#
The provided code demonstrates how to programmatically load a HEIC image file, convert it to a JPEG image, and save it as "output.jpg" using C#. Here's a breakdown of the steps:
- Open the HEIC file named "filename.heic" in read mode using
FileStream
. - Load the HEIC image from the file stream into a
HeicImage
object. - Extract the pixel data from the HEIC image in the BGRA32 format, storing it in a byte array.
- Retrieve the width and height of the HEIC image.
- Create a
WriteableBitmap
object with the specified width, height, DPI, pixel format, and palette. - Define a rectangle covering the entire bitmap area.
- Write the extracted pixel data to the
WriteableBitmap
object. - Create or open a file stream for saving the converted image as "output.jpg".
- Create a
JpegBitmapEncoder
object to encode the bitmap as a JPEG image. - Add the bitmap frame to the encoder.
- Save the encoded image to the file stream.
Copy and paste the code snippet below into your main file and execute the program.
Convert .heic file to .jpg using WriteableBitmap
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);
}
Convert HEIC collection to a set of PNG files programatically in C#
The provided code demonstrates how to programmatically load a HEIC collection image file, convert it to a set of PNG files, and save it using C#. Here's a breakdown of the steps:
- Open the HEIC file named "filename.heic" in read mode using
FileStream
. - Load the HEIC image from the file stream into a
HeicImage
object. - For each frame of the image do the following:
- Extract the pixel data from the HEIC image in the BGRA32 format, storing it in a byte array.
- Retrieve the width and height of the HEIC image.
- Create a
WriteableBitmap
object with the specified width, height, DPI, pixel format, and palette. - Define a rectangle covering the entire bitmap area.
- Write the extracted pixel data to the
WriteableBitmap
object. - Create or open a file stream for saving the converted image as "output.png".
- Create a
PngBitmapEncoder
object to encode the bitmap as a PNG image. - Add the bitmap frame to the encoder.
- Save the encoded image to the file stream.
Copy and paste the code snippet below into your main file and execute the program.
Convert .heic collection to a set of .png files
using (var fs = new FileStream("filename.heic", FileMode.Open))
{
HeicImage image = HeicImage.Load(fs);
foreach (var key in image.Frames.Keys)
{
var width = (int)image.Frames[key].Width;
var height = (int)image.Frames[key].Height;
var pixels = image.Frames[key].GetByteArray(FileFormat.Heic.Decoder.PixelFormat.Bgra32);
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"+key+".png", FileMode.OpenOrCreate);
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(wbitmap));
encoder.Save(saveStream);
}
}
FileFormat.HEIC offers an intuitive API, comprehensive format support, and seamless integration with C# applications, empowering developers and users alike to effortlessly manage HEIC files. Whether you're converting HEIC files for web usage, archiving iPhone photos to a PC, or sharing them across different platforms, FileFormat.HEIC simplifies the process, ensuring optimal efficiency and quality at every step.
Explore our GitHub repository to contribute, suggest improvements, and enhance this Open Source API: FileFormat.HEIC-for-.NET