gpt4 book ai didi

C# 如何打开 HEIC 图像

转载 作者:行者123 更新时间:2023-12-03 14:29:21 32 4
gpt4 key购买 nike

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

在 Google 中搜索 C# 和 HEIC 一无所获,因此似乎尚未解决此问题。

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

谢谢

最佳答案

互联网上有很多关于阅读 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 文件并以像素为单位查看它。

关于C# 如何打开 HEIC 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48854594/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com