Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extrace apk icon, encouter image: unknown format #89

Open
bourne-3 opened this issue Mar 25, 2024 · 3 comments
Open

extrace apk icon, encouter image: unknown format #89

bourne-3 opened this issue Mar 25, 2024 · 3 comments

Comments

@bourne-3
Copy link

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

@shogo82148
Copy link
Owner

It looks that the icon is an adaptive icon.
see #41 (comment) for workaround.

@shogo82148
Copy link
Owner

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)
	}
}

@xja
Copy link

xja commented May 31, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants