androidbinary icon indicating copy to clipboard operation
androidbinary copied to clipboard

extrace apk icon, encouter image: unknown format

Open bourne-3 opened this issue 1 year ago • 3 comments

My requirement is to extract the icon file from the apk file

Here is the code:

func ExtractIcon() {
	apkPath := "/Users/selwyn/Desktop/taptap_2.68.4-mkt.100000_sem.apk"

	pkg, err := apk.OpenFile(apkPath)
	if err != nil {
		panic(err)
	}
	defer pkg.Close()

	icon, err := pkg.Icon(nil) // returns the icon of APK as image.Image
	if err != nil {
		panic(err)
	}
	fmt.Println(icon)
}

image: unknown format error show; Here is the apk file download link:https://d2.tapurl.com/latest/sem-360ss_cn03syyx2_id235106

How can i solve thie problem,thx

bourne-3 avatar Mar 25 '24 08:03 bourne-3

It looks that the icon is an adaptive icon. see https://github.com/shogo82148/androidbinary/issues/41#issuecomment-850860408 for workaround.

shogo82148 avatar Mar 26 '24 13:03 shogo82148

It works on my environment.

package main

import (
	"image/png"
	"os"

	"github.com/shogo82148/androidbinary"
	"github.com/shogo82148/androidbinary/apk"
)

func main() {
	apkPath := "taptap_2.68.4-mkt.100000_sem.apk"

	pkg, err := apk.OpenFile(apkPath)
	if err != nil {
		panic(err)
	}
	defer pkg.Close()

	icon, err := pkg.Icon(&androidbinary.ResTableConfig{
		SDKVersion: 25,
	})
	if err != nil {
		panic(err)
	}

	f, err := os.Create("icon.png")
	if err != nil {
		panic(err)
	}
	if err := png.Encode(f, icon); err != nil {
		panic(err)
	}
	if err := f.Close(); err != nil {
		panic(err)
	}
}

shogo82148 avatar Mar 26 '24 13:03 shogo82148

It works on my environment.

package main

import (
	"image/png"
	"os"

	"github.com/shogo82148/androidbinary"
	"github.com/shogo82148/androidbinary/apk"
)

func main() {
	apkPath := "taptap_2.68.4-mkt.100000_sem.apk"

	pkg, err := apk.OpenFile(apkPath)
	if err != nil {
		panic(err)
	}
	defer pkg.Close()

	icon, err := pkg.Icon(&androidbinary.ResTableConfig{
		SDKVersion: 25,
	})
	if err != nil {
		panic(err)
	}

	f, err := os.Create("icon.png")
	if err != nil {
		panic(err)
	}
	if err := png.Encode(f, icon); err != nil {
		panic(err)
	}
	if err := f.Close(); err != nil {
		panic(err)
	}
}

I still got this unknown format error with SDKVersion: 25 specified.

xja avatar May 31 '24 14:05 xja