开发者

Save the wallpaper of an Android device as a picture

I need to write a program that gets the current wallpaper of an android device and save it to the images folder.

The problem is that I cannot find any information on how to convert the Drawable to a JPEG/PNG

This is my code:

android.graphics.drawabl开发者_如何学运维e.Drawable currentWallpaper = getWallpaper();

How do I convert this Drawable into a JPEG/PNG file?


Don't use getWallpaper() as it is deprecated.

Use WallpaperManager#getDrawable() instead:

WallpaperManager wpm = WallpaperManager.getInstance();
Drawable d = wpm.getDrawable ();
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();


As previously mentioned here, take a look at http://www.brighthub.com/mobile/google-android/articles/30676.aspx. This discusses basically rendering your Drawable on a Canvas backed by a bitmap. You can then save the Bitmap to file using Bitmap.compress.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜