我有大小为 1080P 的图像,现在我不想使用我们放在 RES 文件夹中的图像的不同变体。我打算在带有随机图像的 1K 设备上安装这个应用程序,因此拥有不同版本的图像是不可行的。
我们可以在运行时扩展它,仍然获得最好的质量吗?
我有大小为 1080P 的图像,现在我不想使用我们放在 RES 文件夹中的图像的不同变体。我打算在带有随机图像的 1K 设备上安装这个应用程序,因此拥有不同版本的图像是不可行的。
我们可以在运行时扩展它,仍然获得最好的质量吗?
要缩放图像,请使用以下
Bitmap bitmap = BitmapFactory.decodeResource(
getResources(), R.drawable.app_bg);
scaledBitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
然后将其分配scaledBitmap
给任何ImageView
或任何其他View
. 这会将原件缩放Bitmap
到请求的width
和height
. 要获取设备屏幕的宽度和高度,请使用以下
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
编辑
为了在使用 this 后处理MemoryLeakException
add 。scaledBitmap.recycle()
Bitmap