1. Home
  2.   Heic
  3.   Openize.Heic for .NET
Openize.Heic for .NET

Openize.Heic for .NET

 
 

Simplify Process of Reading and Converting HEIC Images Using .NET API

Effortlessly edit images with Openize.Heic, a lightweight open-source .NET API, streamlining HEIC files convertion and automation

Openize.Heic for .NET revolutionizes your HEIC image processing experience. In this comprehensive guide, we delve into the functionalities and benefits of leveraging Openize.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.

Openize.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.

Openize.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 Openize.Heic effortlessly into your C# applications, enabling seamless HEIC file handling within your existing workflows.

Previous Next

How to Get Started with Openize.Heic for .NET

Getting started with Openize.Heic is quick and easy. Simply follow these steps:

  • Install Openize.Heic: Install the Openize.Heic package via NuGet Package Manager or .NET CLI.
  • Integrate with Your Project: Reference the Openize.Heic library in your C# project.
  • Start Converting: Utilize the simple API provided by Openize.Heic to convert HEIC files to your desired format.

The recommended way to install Openize.Heic for .NET is using NuGet. Please use the following command for a smooth installation.

Install Openize.Heic for .NET via NuGet

NuGet> Install-Package Openize.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 Bitmap 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);
}

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 (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);
    }
}

Openize.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, Openize.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: Openize.HEIC-for-.NET