gpt4 book ai didi

android - 将 Android 矢量绘图转换为启动器图标 PNG

转载 作者:行者123 更新时间:2023-12-05 00:14:20 25 4
gpt4 key购买 nike

我已将 Android 启动器图标制作为矢量,但我发现我应该使用 PNG 而不是矢量 (XML)。如何将我的矢量图像转换为 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.3 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,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>

最佳答案

您需要做的就是:

  1. 在 ImageView 中渲染 Vector
  2. 从 ImageView 获取位图
  3. 将位图保存为 PNG 文件

在 ImageView 中渲染 Vector:

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

从 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
//--------------------------------------------------------------------------------

关于android - 将 Android 矢量绘图转换为启动器图标 PNG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41373074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com