惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
H
Help Net Security
云风的 BLOG
云风的 BLOG
Apple Machine Learning Research
Apple Machine Learning Research
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
D
Docker
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
博客园 - Franky
B
Blog RSS Feed
Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
量子位
V
Visual Studio Blog
Y
Y Combinator Blog
小众软件
小众软件
N
Netflix TechBlog - Medium
博客园 - 三生石上(FineUI控件)
Microsoft Security Blog
Microsoft Security Blog
雷峰网
雷峰网

博客园 - 在路上...

账号复活了 2015年,即将结束 CentOS 6 minimal 安装之后添加gnome Windows8离线安装.net framework 3.5 新年快到了,此记 flex中ComboBox对应的几种数据绑定 - 在路上... - 博客园 Jquery中增加参数与Json转换代码 - 在路上... - 博客园 如何获取到informix for linux? 建国大业 《红》mp3下载 T42内存升级 随便一帖 Informix 9.40UC9 on Redhat Linux AS 4安装手记 Taking the web Offline and On the Desktop Flex上传文件功能 Flex实现QQ网页提取天气信息 乱弹ruby on rails目录下面的文件数有3万多个 Ruby on rails 2.0.2傻瓜入门之Hello world Javascript代码压缩、加密算法的破解分析及工具实现 【翻译】Oracle不同版本之间Export & Import的兼容性矩阵
Iphone的HEIC图片文件格式转换及相关开发工具
在路上... · 2020-08-26 · via 博客园 - 在路上...

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

2、批量转换工具

如果需要批量的转换工具,可以下载下面的免费工具

里面附带的dll可以供开发编程使用

opencv_ffmpeg330_64.dll

opencv_world330.dll

HUD.dll

3、程序处理

可以下载下面的Dll,这个dll封装了opencv相关api接口,提供了转换的接口,接口可以通过C、C#、JNI等来调用

C语言调用工具

 1 #include <iostream>
 2 #include <cstring>
 3 #include <fstream>
 4 #include <sstream>
 5 #include <windows.h>
 6 
 7 using namespace std;
 8 typedef  void (__stdcall *heif2jpg)(const char heif_bin[], int input_buffer_size, const int jpg_quality,
 9                                     char output_buffer[], int output_buffer_size, const char* input_temp_filename,
10                                     int* copysize, bool include_exif, bool color_profile, const char icc_bin[], int icc_size);
11 //读取文件内容
12 ostringstream readBinFile(char* filename,int &size)
13 {
14     fstream fs;
15     fs.open(filename, ios::in|ios::binary);
16     ostringstream oss;
17     oss << fs.rdbuf();
18     size=oss.str().length();
19     fs.close();
20     return oss;
21 }
22 
23 int main(int argc, char *argv[])
24 {
25     cout <<"Heic Convert Tool V1.0 <By midea0978>"<<endl;
26     cout <<"====================================\n"<<endl;
27     int quality=80;
28     if(argc<2)
29     {
30         cout <<"heic.exe <heic文件名> [jpg质量1-100,默认80]\n\n"<<endl;
31         return -1;
32     }
33     if(argc>=3) quality=atoi(argv[2]);
34     HMODULE hModule;
35     hModule = LoadLibraryA("HUD.dll");
36     if ( NULL == hModule)
37     {
38         DWORD error_id=GetLastError();
39         cout<<"加载hud.dll失败:"<<error_id<<endl;
40         return -1;
41     }
42     heif2jpg func = NULL;
43     func = (heif2jpg)GetProcAddress(hModule, "heif2jpg");
44     char drive[_MAX_DRIVE];
45     char dir[_MAX_DIR];
46     char fname[_MAX_FNAME];
47     char ext[_MAX_EXT];
48     _splitpath(argv[1], drive, dir, fname, ext);
49     string ofilename;
50     ofilename+=drive;
51     ofilename+=dir;
52     ofilename+=fname;
53     ofilename+=".jpg";
54     printf("输出JPG文件 %s\n",ofilename.c_str());
55     int imgsize=0;
56     ostringstream heicdata=readBinFile(argv[1],imgsize);
57     int outsize=10*imgsize;
58     char* outbuffer;
59     int copysize[]= {0};
60     outbuffer = (char*)malloc(outsize);
61     memset(outbuffer, 0, outsize);
62     char temppath[MAX_PATH];
63     GetTempPath(MAX_PATH,temppath);
64     string tempfile;
65     tempfile+=temppath;
66     tempfile+="\\temp.dat";
67     func(heicdata.str().c_str(),imgsize,quality,outbuffer,outsize,tempfile.c_str(),copysize,true,false,NULL,0);
68     ofstream outfile(ofilename,ios::binary);
69     outfile.write(outbuffer,copysize[0]);
70     outfile.close();
71     remove(tempfile.c_str());
72     FreeLibrary(hModule);
73     return 0;
74 }

对应C#的调用方式,代码来自于下面的URL

 1 [DllImport("HUD.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
 2 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);
 3 
 4 [DllImport("HUD.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
 5 private unsafe extern static void getexif(byte* heif_bin, int input_buffer_size, byte* ouput_buffer, int output_buffer_size, int* copysize);
 6 
 7 public static unsafe byte[] invoke_heif2jpg(byte[] heif_bin, int jpg_quality, string temp_filename, ref int copysize, bool include_exif, bool color_profile)
 8 {
 9     if (color_profile == true && DisplayP3Profile.Length == 1)
10         throw new Exception();//没有ICC却指定要写入ICC
11 
12     var output_buffer = new byte[heif_bin.Length * 10];
13     byte[] temp_filename_byte_array = System.Text.Encoding.Default.GetBytes(temp_filename);
14     int[] copysize_array = new int[1] { 0 };
15     fixed (byte* input = &heif_bin[0], output = &output_buffer[0], temp_filename_byte = &temp_filename_byte_array[0], icc_ptr = &DisplayP3Profile[0])
16     fixed (int* copysize_p = &copysize_array[0])
17     {
18         heif2jpg(input, heif_bin.Length, jpg_quality, output, output_buffer.Length, temp_filename_byte, copysize_p, include_exif, color_profile, icc_ptr, DisplayP3Profile.Length);
19     }
20     copysize = copysize_array[0];
21     return output_buffer;
22 }
23 
24 public static unsafe string invoke_getexif(byte[] heif_bin, ref int copysize)
25 {
26     var output_buffer = new byte[65535];
27     int[] copysize_array = new int[1] { 0 };
28     fixed (byte* input = &heif_bin[0], output = &output_buffer[0])
29     fixed (int* copysize_p = &copysize_array[0])
30     {
31         getexif(input, heif_bin.Length, output, output_buffer.Length, copysize_p);
32     }
33     copysize = copysize_array[0];
34     return Encoding.Default.GetString(output_buffer, 0, copysize);
35 }

详细代码参考: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等格式一起使用。