2

I see that menu image file is presented like this

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportHeight="24.0"
    android:viewportWidth="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0" />
    <path
        android:fillColor="#FF000000"
        android:pathData="M9,2L7.17,4H4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2H9zm3,15c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z" />
</vector>

enter image description here

I would like to know if there is any tool to convert PNG file to

 android:pathData="M9,2L7.17,4H4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2H9zm3,15c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z" />

and vise versa.

NoWar
  • 36,338
  • 80
  • 323
  • 498

2 Answers2

2

This question is basically asking if it is possible to convert a raster image (PNG) to a vector graphic (VectorDrawable). There are many tools out there to do this but they all have limitations.

First, you should convert the PNG to a SVG. I have used ImageMagic in the past with fair results. For more options and information see these two StackOverflow posts:

ImageMagick png to svg Image Size

How to convert a PNG image to a SVG?

After you convert your PNG to a SVG, you can then use Android SVG to VectorDrawable.


If you want to convert an Android VectorDrawable to a PNG, you need to first convert the drawable to a SVG. I wrote a simple command-line tool (vector2svg) to do this. After you have the SVG there are many tools to convert the SVG to a PNG (just Google for one).

Edit: You can also save the VectorDrawable as a PNG on Android using the following method:

public static void vectorDrawableToPng(Context context, int drawableId, File file)
        throws IOException {
    final Drawable vectorDrawable = context.getResources().getDrawable(drawableId);
    // Convert the VectorDrawable to a Bitmap
    final Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
            vectorDrawable.getIntrinsicHeight(), Config.ARGB_8888);
    final Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    vectorDrawable.draw(canvas);
    // Save the Bitmap as a PNG.
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(file, false);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
        fos.flush();
    } finally {
        if (fos != null) {
            fos.close();
        }
    }
}

I don't recommend converting a PNG to a vector, but the above should answer the question.

Community
  • 1
  • 1
Jared Rummler
  • 37,824
  • 19
  • 133
  • 148
1

As I was searching for a way to change Menu Icons I found this website material.io/icons

Where you can find lots of Icons and also download them as SVG or even PNG

M at
  • 1,020
  • 1
  • 12
  • 26