首页 > 其他 > 详细

Iphone中HEIC文件格式转换及相关工具

时间:2020-08-26 13:54:25      阅读:94      评论:0      收藏:0      [点我收藏+]

1、Windows 10安装插件查看heic图片

Windows10上默认无法打开Apple的HEVC&HEIC格式文件,需要安装相应的扩展,在 Microsoft Store里查找会发现“HEVC视频扩展”是一个付费应用!(在国外的Microsoft Store里此扩展是免费的。实际上在品牌机预装Win10中会自带一个“来自设备制造商的HEVC视频扩展”,功能和付费的是一样的。但是你无法在Microsoft Store内直接搜索到这个扩展。

解决办法:
浏览器中直接打开如下链接:
https://www.microsoft.com/en-us/p/hevc-video-extensions-from-device-manufacturer/9n4wgh0z6vhq
点击“获取”就会自动打开Microsoft Store来安装此扩展了。

2、批量转换工具
如果需要批量的转换工具,可以下载下面的免费工具
 
里面附带的dll可以供开发编程使用
opencv_ffmpeg330_64.dll
opencv_world330.dll
HUD.dll
 
3、程序处理
可以下载下面的Dll,这个dll封装了opencv相关api接口,提供了转换的接口,接口可以通过C、C#、JNI等来调用
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 = &copysize_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 = &copysize_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等格式一起使用。

 

Iphone中HEIC文件格式转换及相关工具

原文:https://www.cnblogs.com/midea0978/p/13564458.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!