【问题标题】:C# How to Open HEIC ImageC# 如何打开 HEIC 图像
【发布时间】:2018-07-29 00:07:17
【问题描述】:

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

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

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

谢谢

【问题讨论】:

  • 文件就是文件。就文件上传而言,它是什么类型并不重要。现在,如果您已采取措施限制文件类型,导致这种特定格式无法正常工作,那么您需要具体说明哪些问题不起作用,提供minimal reproducible example 等。
  • 有了我有一个图片上传表单,你的意思是你还必须显示/转换这些图片?如果是这种情况,请查看以下 GitHub 项目:Magick.NETHEIF-UtilityISOBMFF (c++ Library)
  • 谢谢,这就是我想要的。为什么对这个问题投反对票?
  • 不幸的是,所有这些解决方案都依赖于非托管 DLL,因此在 Linux 上使用 MONO 变得更加困难。
  • @EtienneCharland 你找到工作了吗?

标签: c# asp.net


【解决方案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。 正如第一个答案所说,由于谷歌浏览器支持 h264,所以它应该支持 heic..
但这将是一个非常困难的解决方案,需要做太多工作,所以我建议只在服务器上转换 heic 或编写一个自定义脚本,让您读取 heic 文件并以像素为单位查看它..

【讨论】:

    猜你喜欢
    • 2018-02-21
    • 2021-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-18
    • 2019-06-21
    • 1970-01-01
    相关资源
    最近更新 更多