在开发 Android 应用程序时,我看到资产中显示的所有图像都是像素化的。
我正在使用这 2 行来显示它们:
Drawable imageDrawable = Drawable.createFromStream("my_logo.png", null);
imageView.setBackground(imageDrawable);
图像的尺寸为:128/128 或 256/256,并显示在方形 ImageView 中。
有人想保持我的图像质量吗?
更改图像的尺寸会降低质量。你可以做几件事
ImageView
与图像大小相同或更小的高度和宽度,并保持纵横比。
void setImageDrawable (Drawable drawable)
将可绘制对象设置为 ImageView 的内容。
要将drawable设置为ImageView
从java,您需要使用setImageDrawable (Drawable drawable)
方法。
您正在将可绘制对象设置为 imageView 的背景,您的代码应该是,
Drawable imageDrawable = Drawable.createFromStream("my_logo.png", null);
imageView.setImageDrawable(imageDrawable);