Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# How to Open HEIC Image

Tags:

c#

asp.net

I have an image upload form in ASP.NET that supports JPG/PNG/GIF and I thought it would be enough. Until Apple introduced their new HEIC image format. How do I handle that in C#?

Searching for C# and HEIC shows nothing in Google, so it seems this issue hasn't been addressed yet.

Does the .NET Framework support HEIC out-of-the-box? Probably not since it's so new. Is there any 3rd party library that supports it? I want to convert HEIC to JPG for storage.

Thanks

like image 756
Etienne Charland Avatar asked Feb 18 '18 17:02

Etienne Charland


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.


1 Answers

There are tons of answers out there on the internet about reading heic files, converting them to different other file formats:
Converting .HEIC to JPEG using imagick in C#.

and

https://medium.com/@cloudmersive/how-to-convert-heic-to-png-using-c-in-net-framework-d73ae7d4609e 's solution to. convert heic to png using

Cloudmersive.APIClient.NET.DocumentAndDataConvert 

NuGet package.

//Program.cs
using System;
using System.Diagnostics;
using  Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;
namespace Example
{
public class ConvertImageImageFormatConvertExample
{
    public static void Main()
    {
        // Configure API key authorization: Apikey
        Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
        // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
        // 
Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");
var apiInstance = new ConvertImageApi();
        var format1 = format1_example;  // string | Input file format as a 3+ letter file extension.  You can also provide UNKNOWN for unknown file formats. Supported formats include AAI, ART, ARW, AVS, BPG, BMP, BMP2, BMP3, BRF, CALS, CGM, CIN, CMYK, CMYKA, CR2, CRW, CUR, CUT, DCM, DCR, DCX, DDS, DIB, DJVU, DNG, DOT, DPX, EMF, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EXR, FAX, FIG, FITS, FPX, GIF, GPLT, GRAY, HDR, HEIC, HPGL, HRZ, ICO, ISOBRL, ISBRL6, JBIG, JNG, JP2, JPT, J2C, J2K, JPEG/JPG, JXR, MAT, MONO, MNG, M2V, MRW, MTV, NEF, ORF, OTB, P7, PALM, PAM, PBM, PCD, PCDS, PCL, PCX, PDF, PEF, PES, PFA, PFB, PFM, PGM, PICON, PICT, PIX, PNG, PNG8, PNG00, PNG24, PNG32, PNG48, PNG64, PNM, PPM, PSB, PSD, PTIF, PWB, RAD, RAF, RGB, RGBA, RGF, RLA, RLE, SCT, SFW, SGI, SID, SUN, SVG, TGA, TIFF, TIM, UIL, VIFF, VICAR, VBMP, WDP, WEBP, WPG, X, XBM, XCF, XPM, XWD, X3F, YCbCr, YCbCrA, YUV
        var format2 = format2_example;  // string | Output (convert to this format) file format as a 3+ letter file extension.  Supported formats include AAI, ART, ARW, AVS, BPG, BMP, BMP2, BMP3, BRF, CALS, CGM, CIN, CMYK, CMYKA, CR2, CRW, CUR, CUT, DCM, DCR, DCX, DDS, DIB, DJVU, DNG, DOT, DPX, EMF, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EXR, FAX, FIG, FITS, FPX, GIF, GPLT, GRAY, HDR, HEIC, HPGL, HRZ, ICO, ISOBRL, ISBRL6, JBIG, JNG, JP2, JPT, J2C, J2K, JPEG/JPG, JXR, MAT, MONO, MNG, M2V, MRW, MTV, NEF, ORF, OTB, P7, PALM, PAM, PBM, PCD, PCDS, PCL, PCX, PDF, PEF, PES, PFA, PFB, PFM, PGM, PICON, PICT, PIX, PNG, PNG8, PNG00, PNG24, PNG32, PNG48, PNG64, PNM, PPM, PSB, PSD, PTIF, PWB, RAD, RAF, RGB, RGBA, RGF, RLA, RLE, SCT, SFW, SGI, SID, SUN, SVG, TGA, TIFF, TIM, UIL, VIFF, VICAR, VBMP, WDP, WEBP, WPG, X, XBM, XCF, XPM, XWD, X3F, YCbCr, YCbCrA, YUV
        var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.
try
        {
            // Image format conversion
            byte[] result = apiInstance.ConvertImageImageFormatConvert(format1, format2, inputFile);
            Debug.WriteLine(result);
        }
        catch (Exception e)
        {
            Debug.Print("Exception when calling ConvertImageApi.ConvertImageImageFormatConvert: " + e.Message );
        }
    }
}
}

But as you are in asp.net I suppose you need to open the image in an html webpage, not to edit it.
The question is not really about csharp..

https://www.quora.com/Does-Google-Chrome-support-heif-images. As in the first answer is said, as Google Chrome supports h264, so it should support heic..
But it would be a very hard solution, which would require too much work to do, so I either recommend just converting heic on the server or writing a custom script that will allow you to read the heic file and view it in pixels..

like image 130
Daniel Avatar answered Sep 18 '22 19:09

Daniel