本文介绍了C#如何打开HEIC图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

搜索C#和HEIC在Google中什么都没有显示,因此似乎尚未解决此问题.

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

谢谢

解决方案

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

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使用系统;使用System.Diagnostics;使用Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;使用Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;使用Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;命名空间示例{公共类ConvertImageImageFormatConvertExample{公共静态void Main(){//配置API密钥授权:ApikeyConfiguration.Default.AddApiKey("Apikey","YOUR_API_KEY");//如果需要,请在下面取消注释以设置API密钥的前缀(例如Bearer)//Configuration.Default.AddApiKeyPrefix("Apikey","Bearer");var apiInstance = new ConvertImageApi();var format1 = format1_example;//字符串|输入文件格式为3+字母文件扩展名.您也可以为未知文件格式提供UNKNOWN.支持的格式包括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,传真,图,FITS,FPX,GIF,GPLT,灰色,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,YUVvar format2 = format2_example;//字符串|输出(转换为这种格式)文件格式为3+字母文件扩展名.支持的格式包括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,传真,图,FITS,FPX,GIF,GPLT,灰色,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,YUVvar inputFile = new System.IO.Stream();//System.IO.Stream |输入文件以执行操作.尝试{//图像格式转换byte []结果= apiInstance.ConvertImageImageFormatConvert(format1,format2,inputFile);Debug.WriteLine(结果);}捕获(异常e){Debug.Print("调用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>

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

解决方案

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

这篇关于C#如何打开HEIC图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 02:03