【发布时间】:2021-08-29 03:00:21
【问题描述】:
我有一个代码可以加载图像的缩略图并将其提供给滑行。然后滑翔将加载到支架中。但是,当我加载缩略图时,它会返回一个位图。所以,我将位图传递给滑行。但是,初始加载需要将近 30 秒。我的意思是在画廊里有很多照片。因此,当画廊打开时,它根本不会显示 30 秒的图像。然后它会显示位图。
另一方面,如果我使用 URI 来馈送滑行,它会立即加载它。但是,图像正在回收站视图中加载。因此,当时只会加载一些图像。
加载一些图像后。当我们向上滑动并查看其他照片的加载速度时,显然位图馈送图像的加载速度比 URI 馈送图像更快。但是,位图需要 30 秒的初始加载时间。
有什么方法可以让这个位图加载更快?
...
while (cursor.moveToNext()) {
Log.d("FetchImages(): ", " Started");
Bitmap thumbBitmap = null;
int _thumpId = cursor.getInt(column_index_data);
Uri uri1 = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, _thumpId);
Size thumbSize = new Size(150, 150);
try {
thumbBitmap = getApplicationContext().getContentResolver().loadThumbnail(uri1, thumbSize, null);
} catch (IOException e) {e.printStackTrace();}
ImageModel ImageModel = new ImageModel();
ImageModel.setBitmap(thumbBitmap);
arrayList.add(ImageModel);
}
Log.d("FetchImages(): ", " Ended");
runOnUiThread(() -> {
Adapter Adapter = new Adapter(getApplicationContext(), arrayList, MainActivity.this);
recyclerView.setAdapter(Adapter);
cursor.close();
Log.d("FetchImages(): ", " RecyclerView Adapter attached");
});
...
【问题讨论】:
标签: android bitmap uri thumbnails android-glide