I\'ve made Android launcher icon as vector but I found out that I should use PNGs instead of vector(XML). How can I convert my vector image to PNGs for launcher icon.
Thi
All you need to do is:
render the Vector in an ImageView:
//--------------------------------------------------------------------------------
ImageView image = R.findViewById(R.id.imageView);//get ImageView
//--------------------------------------------------------------------------------
get the Bitmap from the ImageView:
//--------------------------------------------------------------------------------
Bitmap bitmap = ((BitmapDrawable)image.getDrawable()).getBitmap();//get Bitmap
SaveImage(bitmap,"my_png_file");//save it
//--------------------------------------------------------------------------------
Save the Bitmap to a PNG file:
//--------------------------------------------------------------------------------
private void SaveImage(Bitmap finalBitmap, String filename)
{
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/saved_images");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = filename +".png";
File file = new File (myDir, fname);
if (file.exists ()) file.delete ();
try {
FileOutputStream out = new FileOutputStream(file);
finalBitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
sendBroadcast(new Intent(
Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));
} catch (Exception e) {
e.printStackTrace();
}
}//SaveImage
//--------------------------------------------------------------------------------