C#如何打开HEIC图像

时间:2018-02-18 17:32:14

标签: c# asp.net

我在ASP.NET中有一个支持JPG / PNG / GIF的图像上传表单,我认为这就足够了。直到Apple推出他们的新HEIC图像格式。我如何在C#中处理它?<​​/ p>

搜索C#和HEIC在Google中没有显示任何内容,因此似乎尚未解决此问题。

.NET Framework是否支持HEIC开箱即用?可能不是因为它太新了。是否有支持它的第三方库?我想将HEIC转换为JPG进行存储。

由于

1 个答案:

答案 0 :(得分:1)

互联网上有大量有关读取heic文件并将其转换为其他文件格式的答案:
Converting .HEIC to JPEG using imagick in C#

https://medium.com/@cloudmersive/how-to-convert-heic-to-png-using-c-in-net-framework-d73ae7d4609e的解决方案。使用

将heic转换为png
Cloudmersive.APIClient.NET.DocumentAndDataConvert 

NuGet程序包。

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

但是当您进入asp.net时,我想您需要在html网页中打开图片,而不要对其进行编辑。
问题不是关于csharp的。.

https://www.quora.com/Does-Google-Chrome-support-heif-images。 就像第一个答案所说的那样,因为Google Chrome支持h264,所以它应该支持heic ..
但这将是一个非常困难的解决方案,需要做很多工作,因此我建议仅在服务器上转换heic或编写自定义脚本,以允许您读取heic文件并以像素为单位查看。 / p>