apk中提取图标
需要引用庫:ICSharpCode.SharpZipLib.dll
圖標路徑:
? ? //texture path
? ? string first = "res/mipmap-xxxhdpi-v4/app_icon.png";
? ? string second = "res/drawable-xxxhdpi-v4/app_icon.png";
? ? string third = "res/drawable-hdpi-v4/app_icon.png";
? ? string fourth = "res/drawable-mdpi-v4/app_icon.png";
? ? //string fifth = "res/drawable-ldpi-v4/app_icon.png";
? ? string inputPath = "E:\\apk\\Camera.apk";
? ? string outputPath = "E:\\apk\\UnZip\\";
?
圖片的輸出路徑與輸入路徑相同
public void GetIconFromAPK(string inputpath, string outputpath)
? ? {
? ? ? ? if (!File.Exists(inputpath))
? ? ? ? {
? ? ? ? ? ? Debug.LogError("Inputpath doesn't exist");
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? if (!Directory.Exists(outputpath))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Directory.CreateDirectory(outputpath);
? ? ? ? ? ? }
? ? ? ? ? ? string fileName = Path.GetFileName(inputpath).Replace(".apk", ".png");
? ? ? ? ? ? ZipFile file = new ZipFile(inputpath);
? ? ? ? ? ? //判斷壓縮文件中是否存在該文件
? ? ? ? ? ? ZipEntry entry;
? ? ? ? ? ? entry = file.GetEntry(first);
? ? ? ? ? ? if (entry == null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? entry = file.GetEntry(second);
? ? ? ? ? ? }
? ? ? ? ? ? if (entry == null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? entry = file.GetEntry(third);
? ? ? ? ? ? }
? ? ? ? ? ? if (entry == null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? entry = file.GetEntry(fourth);
? ? ? ? ? ? ? ? Debug.LogError("Didn't find icon");
? ? ? ? ? ? }
? ? ? ? ? ? if (entry != null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? using (var s = file.GetInputStream(entry))
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? using (FileStream streamWriter = File.Create(outputpath + fileName))
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? byte[] data = new byte[2048];
? ? ? ? ? ? ? ? ? ? ? ? int size = 0;
? ? ? ? ? ? ? ? ? ? ? ? while (true)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? size = s.Read(data, 0, data.Length);
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (size > 0)
? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? streamWriter.Write(data, 0, size);
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
?
僅限apk中圖片名為app_icon.png,manifest中可以讀取到icon的位置,尚未研究
總結
- 上一篇: 火狐浏览器Firefox如何导出导入书签
- 下一篇: python实现对文本内容的修改_介绍p