16

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

Etienne Charland
  • 3,424
  • 5
  • 28
  • 58
  • A file is a file. It doesn't matter what type it is as far as a file upload is concerned. Now, if you've done something to limit file types that causes this particular format not to work, then you would need to specifically explain what's not working about it, provide a [MCVE] etc. – mason Feb 18 '18 at 17:50
  • 4
    With *I have an image upload form*, you mean that you also have to show/convert those images? If that's the case, take a look at these GitHUb projects: [Magick.NET](https://github.com/dlemstra/Magick.NET), [HEIF-Utility](https://github.com/liuziangexit/HEIF-Utility), [ISOBMFF (c++ Library)](https://github.com/DigiDNA/ISOBMFF) – Jimi Feb 18 '18 at 18:28
  • 3
    Thanks, that's what I was looking for. Why the downvotes on the question? – Etienne Charland Feb 21 '18 at 21:31
  • 2
    Unfortunately, all of these solutions depend on non-managed DLLs, and thus makes it a lot harder to use with MONO on Linux. – Etienne Charland Feb 21 '18 at 22:34
  • 1
    @EtienneCharland did you find a work around? – coder771 Mar 06 '18 at 08:17
  • I haven't looked into compiling the library on Linux, it would require a lot of time and last time I tried for another library I hadn't got it working. – Etienne Charland Mar 06 '18 at 21:31

1 Answers1

2

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

Daniel
  • 93
  • 7