3
ArrayList<String> imageFileList = new ArrayList<>();
ArrayList<RecentImagesModel> fileInfo = new ArrayList<>();
File targetDirector = new File(/storage/emulated/0/DCIM/Camera/);
if (targetDirector.listFiles() != null) {
File[] files = targetDirector.listFiles();
int i = files.length - 1;
while (imageFileList.size() < 10) {
File file = files[i];
if (file.getAbsoluteFile().toString().trim().endsWith(".jpg")) {
imageFileList.add(file.getAbsolutePath());
} else if (file.getAbsoluteFile().toString().trim().endsWith(".png")) {
imageFileList.add(file.getAbsolutePath());
}
i--;
}
}
String file, filename;
Bitmap rawBmp, proBmp;
int length = imageFileList.size();
for (int i = 0; i < length; i++) {
RecentImagesModel rim = new RecentImagesModel();
file = imageFileList.get(i);
rim.setFilepath(file);
filename = file.substring(file.lastIndexOf("/") + 1);
rim.setName(filename);
rawBmp = BitmapFactory.decodeFile(file);
proBmp = Bitmap.createScaledBitmap(rawBmp, rawBmp.getWidth()/6, rawBmp.getHeight()/6, false);
rim.setBitmap(proBmp);
fileInfo.add(rim);
}
當我轉換文件對象,位圖和重新調整它們:如何快速將圖像文件路徑列表轉換爲位圖列表?
rawBmp = BitmapFactory.decodeFile(file);
proBmp = Bitmap.createScaledBitmap(rawBmp, rawBmp.getWidth()/6, rawBmp.getHeight()/6, false);
它發生在處理大量的時間。有沒有辦法縮短這個過程?
我需要提供至少10張圖片,不能比這更小。 –
嘗試了原始圖像的1/8,它將圖像快速地綁定到recylerview。但將文件對象轉換爲位圖並將它們存儲在數組列表中仍然需要時間。 –
@ShubhanshJaiswal:如果您使用'RecyclerView',請使用圖像加載庫(Glide,Picasso等)根據需要加載圖像*,而不是預先加載它們。 – CommonsWare