从位图工厂| Android解码时的边缘角/像素化圆形图标
我用两种不同的方法绘制相同的圆形图标,得到不同的结果。一个是完美的圆形,另一个是前卫的 当我尝试在ImageView中显示图像时,我得到了这个结果 当我尝试使用位图解码显示时 获取位图函数从位图工厂| Android解码时的边缘角/像素化圆形图标,android,bitmap,android-bitmap,Android,Bitmap,Android Bitmap,我用两种不同的方法绘制相同的圆形图标,得到不同的结果。一个是完美的圆形,另一个是前卫的 当我尝试在ImageView中显示图像时,我得到了这个结果 当我尝试使用位图解码显示时 获取位图函数 @TargetApi(Build.VERSION_CODES.LOLLIPOP) private static Bitmap getBitmap(VectorDrawable vectorDrawable) { Bitmap bitmap = Bitmap.createBitmap(vectorD
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static Bitmap getBitmap(VectorDrawable vectorDrawable) {
Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
vectorDrawable.draw(canvas);
return bitmap;
}
private static Bitmap getBitmap(Context context, int drawableId) {
Drawable drawable = ContextCompat.getDrawable(context, drawableId);
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
} else if (drawable instanceof VectorDrawable) {
return getBitmap((VectorDrawable) drawable);
} else {
throw new IllegalArgumentException("unsupported drawable type");
}
}
所以,如何使用第二种方法获得像第一种方法一样的圆形图像
非常感谢您的帮助。您的问题是什么?@CzarMatt如何在第二种情况下显示完美圆。您的问题是什么?@CzarMatt如何在第二种情况下显示完美圆。
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static Bitmap getBitmap(VectorDrawable vectorDrawable) {
Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
vectorDrawable.draw(canvas);
return bitmap;
}
private static Bitmap getBitmap(Context context, int drawableId) {
Drawable drawable = ContextCompat.getDrawable(context, drawableId);
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
} else if (drawable instanceof VectorDrawable) {
return getBitmap((VectorDrawable) drawable);
} else {
throw new IllegalArgumentException("unsupported drawable type");
}
}