2016-12-29 46 views
-1


我制作了Android启动器图标作为矢量,但我发现我应该使用PNG而不是矢量(XML)。如何将我的矢量图像转换为用于启动器图标的PNG。转换Android矢量绘制为启动图标PNG

这是矢量,如果它的任何帮助:

<?xml version="1.0" encoding="utf-8"?> 
<layer-list 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:width="100dp" 
    android:height="100dp"> 
    <item> 
     <shape xmlns:android="http://schemas.android.com/apk/res/android" 
       android:shape="oval"> 
      <solid 
       android:color="#5FB0C9"/> 
      <size 
       android:width="100dp" 
       android:height="100dp"/> 
      <stroke 
       android:width="5dip" 
       android:color="#3DA8C9"/> 
     </shape> 
    </item> 
    <item 
     android:gravity="center"> 
     <vector 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:width="60dp" 
      android:height="60dp" 
      android:viewportHeight="100.0" 
      android:viewportWidth="100.0"> 
      <path 
       android:fillColor="#2c819b" 
       android:pathData="M72.4,3.5c-2,0 -3.9,0 -5.9,0c-4.5,0 -7,3.4 -7.5,7.5c-0.9,7.3 -1.8,14.6 -2.7,21.9c2.5,-2.5 5,-5 7.5,-7.5c-7.8,-0.2 -15.6,-0.3 -23.3,-0.5c2.5,2.5 5,5 7.5,7.5c0.9,-7.1 1.8,-14.3 2.7,-21.4c0.5,-4.1 -3.8,-7.5 -7.5,-7.5c-2,0 -3.9,0 -5.8,0c-4.5,0 -7,3.4 -7.5,7.5c-0.9,7.1 -1.8,14.2 -2.7,21.3c2.5,-2.5 5,-5 7.5,-7.5c-7.1,-0.2 -14.3,-0.3 -21.4,-0.5c-3,-0.1 -6.8,2.3 -7.2,5.5c-0.3,1.9 -0.6,3.9 -0.8,5.8c-0.7,4.8 1.9,9.4 7.2,9.5c7.2,0.2 14.4,0.3 21.5,0.5c-2.5,-2.5 -5,-5 -7.5,-7.5c-1,7.7 -1.9,15.4 -2.9,23.2c2.5,-2.5 5,-5 7.5,-7.5c-7.3,-0.2 -14.7,-0.3 -22,-0.5c-3,-0.1 -6.8,2.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.5,7.5c2,0 3.9,0 5.8,0c-2.5,-2.5 -5,-5 -7.5,-7.5c-0.9,7.1 -1.8,14.3 -2.7,21.4c-0.5,4.1 3.8,7.4 7.5,7.5c7.8,0.2 15.6,0.3 23.3,0.5c4.5,0.1 7,-3.5 7.5,-7.5c0.9,-7.3 1.8,-14.6 2.7,-21.9c-2.5,2.5 -5,5 -7.5,7.5c2,0 3.9,0 5.9,0C82.1,18.5 82.1,3.5 72.4,3.5z"/> 
      <path 
       android:fillColor="#2c819b" 
       android:pathData="M60.2,54.3c-7.8,-0.2 -15.6,-0.3 -23.3,-0.5c2.5,2.5 5,5 7.5,7.5c1,-7.7 1.9,-15.4 2.9,-23.2c-2.5,2.5 -5,5 -7.5,7.5c7.8,0.2 15.6,0.3 23.3,0.5c-2.5,-2.5 -5,-5 -7.5,-7.5c-1,7.7 -1.9,15.4 -2.9,23.2c-0.5,4.1 3.8,7.5 7.5,7.5c4.5,0 7,-3.4 7.5,-7.5c1,-7.7 1.9,-15.4 2.9,-23.2c0.5,-4.1 -3.8,-7.4 -7.5,-7.5c-7.8,-0.2 -15.6,-0.3 -23.3,-0.5c-4.5,-0.1 -7,3.5 -7.5,7.5c-1,7.7 -1.9,15.4 -2.9,23.2c-0.5,4.1 3.8,7.4 7.5,7.5c7.8,0.2 15.6,0.3 23.3,0.5C69.9,69.5 69.9,54.5 60.2,54.3z"/> 
     </vector> 
    </item> 
</layer-list> 
+0

我认为这将有助于你HTTPS

//-------------------------------------------------------------------------------- ImageView image = R.findViewById(R.id.imageView);//get ImageView //-------------------------------------------------------------------------------- 

从ImageView的得到位图://android-developers.googleblog.com/2015/09/android-studio-14.html和https://developer.android.com/studio/write/vector-asset-studio.html –

回答

0

所有你需要做的是:

  1. 渲染矢量在ImageView的
  2. 从ImageView的
  3. 获取位图
  4. 将位图保存为PNG文件

渲染矢量在ImageView的:

//-------------------------------------------------------------------------------- 
    Bitmap bitmap = ((BitmapDrawable)image.getDrawable()).getBitmap();//get Bitmap 
    SaveImage(bitmap,"my_png_file");//save it 
//-------------------------------------------------------------------------------- 

保存位图的PNG文件:

//-------------------------------------------------------------------------------- 
    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 
    //-------------------------------------------------------------------------------- 
+0

谢谢你的回答但是我手动将它重写为svg然后用一些网站来制作png。我希望我不会犯同样的错误。你知道是否有办法在桌面上制作这个转换器,这样更方便吗? – TheKarlo95

+0

必须有很多,这里有一个https://github.com/filamentgroup/svg-to-png –