Android 图片来自资产像素化
Android image from asset pixelated
在开发 Android 应用程序时,我发现资产中显示的所有图像都是像素化的。
我用这两行来显示它们:
Drawable imageDrawable = Drawable.createFromStream("my_logo.png", null);
imageView.setBackground(imageDrawable);
图像的尺寸为:128/128 或 256/256,并显示在正方形 ImageView 中。
有没有人有办法保持我的图像质量?
更改图像的尺寸会降低质量。您可以做几件事
- 改用矢量。矢量可以无限放大和缩小而不会降低质量。
- 使用与图片大小相同或更小的
ImageView
高度和宽度,并保持宽高比。
void setImageDrawable (Drawable drawable)
Sets a drawable as the content of ImageView.
要将 drawable 从 java 设置为 ImageView
,您需要使用 setImageDrawable (Drawable drawable)
方法。
您正在将可绘制对象设置为 imageView 的背景,您的代码应该是,
Drawable imageDrawable = Drawable.createFromStream("my_logo.png", null);
imageView.setImageDrawable(imageDrawable);
在开发 Android 应用程序时,我发现资产中显示的所有图像都是像素化的。
我用这两行来显示它们:
Drawable imageDrawable = Drawable.createFromStream("my_logo.png", null);
imageView.setBackground(imageDrawable);
图像的尺寸为:128/128 或 256/256,并显示在正方形 ImageView 中。
有没有人有办法保持我的图像质量?
更改图像的尺寸会降低质量。您可以做几件事
- 改用矢量。矢量可以无限放大和缩小而不会降低质量。
- 使用与图片大小相同或更小的
ImageView
高度和宽度,并保持宽高比。
void setImageDrawable (Drawable drawable)
Sets a drawable as the content of ImageView.
要将 drawable 从 java 设置为 ImageView
,您需要使用 setImageDrawable (Drawable drawable)
方法。
您正在将可绘制对象设置为 imageView 的背景,您的代码应该是,
Drawable imageDrawable = Drawable.createFromStream("my_logo.png", null);
imageView.setImageDrawable(imageDrawable);