-1

我有大小为 1080P 的图像,现在我不想使用我们放在 RES 文件夹中的图像的不同变体。我打算在带有随机图像的 1K 设备上安装这个应用程序,因此拥有不同版本的图像是不可行的。

我们可以在运行时扩展它,仍然获得最好的质量吗?

4

1 回答 1

2

要缩放图像,请使用以下

Bitmap bitmap = BitmapFactory.decodeResource(
                getResources(), R.drawable.app_bg);
scaledBitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);

然后将其分配scaledBitmap给任何ImageView或任何其他View. 这会将原件缩放Bitmap到请求的widthheight. 要获取设备屏幕的宽度和高度,请使用以下

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;

编辑
为了在使用 this 后处理MemoryLeakExceptionadd 。scaledBitmap.recycle()Bitmap

于 2015-09-08T07:47:17.227 回答