1、Windows 10安装插件查看heic图片
解决办法:
浏览器中直接打开如下链接:
https://www.microsoft.com/en-us/p/hevc-video-extensions-from-device-manufacturer/9n4wgh0z6vhq
点击“获取”就会自动打开Microsoft Store来安装此扩展了。
C接口 void heif2jpg(const char heif_bin[], int input_buffer_size, const int jpg_quality, char output_buffer[], int output_buffer_size, const char* input_temp_filename) 作用: 将 Apple HEIF 转换为 JPEG 调用约定: Cdecl 参数 heif_bin: HEIF 文件二进制数据 参数 input_buffer_size: HEIF 文件二进制数据大小 参数 jpg_quality: 设定输出的 JPEG 图像的质量。取值 1-100,数值越高质量越好 参数 output_buffer: JPEG 图像输出缓冲区 参数 output_buffer_size: 输出缓冲区大小 参数 input_temp_filename: 函数运行时将会产生临时文件,通过此参数指定临时文件名。在执行结束后,临时文件可以被删除。 异常: 无
对应C#的调用定义为:
[DllImport("HUD.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] private unsafe extern static void heif2jpg(byte* heif_bin, int input_buffer_size, int jpg_quality, byte* ouput_buffer, int output_buffer_size, byte* temp_filename, int* copysize, bool include_exif, bool color_profile, byte* icc_bin, int icc_size); [DllImport("HUD.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] private unsafe extern static void getexif(byte* heif_bin, int input_buffer_size, byte* ouput_buffer, int output_buffer_size, int* copysize); public static unsafe byte[] invoke_heif2jpg(byte[] heif_bin, int jpg_quality, string temp_filename, ref int copysize, bool include_exif, bool color_profile) { if (color_profile == true && DisplayP3Profile.Length == 1) throw new Exception();//没有ICC却指定要写入ICC var output_buffer = new byte[heif_bin.Length * 10]; byte[] temp_filename_byte_array = System.Text.Encoding.Default.GetBytes(temp_filename); int[] copysize_array = new int[1] { 0 }; fixed (byte* input = &heif_bin[0], output = &output_buffer[0], temp_filename_byte = &temp_filename_byte_array[0], icc_ptr = &DisplayP3Profile[0]) fixed (int* copysize_p = ©size_array[0]) { heif2jpg(input, heif_bin.Length, jpg_quality, output, output_buffer.Length, temp_filename_byte, copysize_p, include_exif, color_profile, icc_ptr, DisplayP3Profile.Length); } copysize = copysize_array[0]; return output_buffer; } public static unsafe string invoke_getexif(byte[] heif_bin, ref int copysize) { var output_buffer = new byte[65535]; int[] copysize_array = new int[1] { 0 }; fixed (byte* input = &heif_bin[0], output = &output_buffer[0]) fixed (int* copysize_p = ©size_array[0]) { getexif(input, heif_bin.Length, output, output_buffer.Length, copysize_p); } copysize = copysize_array[0]; return Encoding.Default.GetString(output_buffer, 0, copysize); }
详细代码参考:https://github.com/liuziangexit/HEIF-Utility/blob/master/HEIF%20Utility/invoke_dll.cs
其他的开源库:
https://github.com/libvips/libvips
ibvips是一个图像处理库。与类似的库相比,libvips运行迅速且几乎不占用内存。libvips是根据LGPL 2.1+许可的。
它具有约300种运算, 涵盖算术,直方图,卷积,形态运算,频率滤波,颜色,重采样,统计等。它支持多种数字类型,从8位int到128位复数。图像可以具有任意数量的波段。它支持各种图像格式,包括JPEG,TIFF,PNG,WebP,HEIC,FITS,Matlab,OpenEXR,PDF,SVG,HDR,PPM / PGM / PFM,CSV,GIF,分析,NIfTI,DeepZoom和OpenSlide 。它还可以通过ImageMagick或GraphicsMagick加载图像,使其与DICOM等格式一起使用。
原文:https://www.cnblogs.com/midea0978/p/13564458.html