smi*_*324 3 java android image bitmap
我正在从磁盘读取图像并将其显示在一行中ListView
.图像文件大于需要ImageView
在行内显示的图像文件.由于我需要缓存bitmaps
内存以便更快地访问,我希望它们只能与ImageView
s 一样大(85x85 dip)
现在我正在阅读文件中
bitmap = BitmapFactory.decodeFile(file);
ImageView负责缩放和裁剪
机器人:scaleType = "centerCrop"
AFAIK这是将整个位图保留在内存中(因为我将其缓存在XD中)并且这很糟糕
如何从ImageView中删除此责任并在加载文件时执行裁剪+缩放?所有位图都将以85x85倾角显示,需要为'centerCrop'
在加载,裁剪和缩放之前,您可以找到图片的尺寸:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
Bitmap bmo = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
Run Code Online (Sandbox Code Playgroud)
然后加载样本大小:
...
options.inSampleSize = 1/2;
bmo = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
...
= Bitmap.createScaledBitmap(bmo, dW, dH, false);
Run Code Online (Sandbox Code Playgroud)
不要忘记回收临时位图,否则你会得到OOME.
bmo.recycle();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13211 次 |
最近记录: |