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的位置,尚未研究

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值