尝试这样的事情:
try{
//get icon from package
String pkg = "com.app.my";//your package name
Drawable icon = getContext().getPackageManager().getApplicationIcon(pkg);
imageView.setImageDrawable(icon);
Bitmap bitmap = drawableToBitmap(icon);
//save bitmap to sdcard
FileOutputStream out;
try {
out = new FileOutputStream(Environment.getExternalStorageDirectory()
+ File.separator + "output.png");
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e) {
e.printStackTrace();
} finally {
//close output stream (important!)
try{
out.close();
} catch(Throwable ignore) {}
}
} catch (PackageManager.NameNotFoundException ne) {}
//convert drawable to a bitmap
public static Bitmap drawableToBitmap (Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable)drawable).getBitmap();
}
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}