【发布时间】:2024-05-15 21:35:02
【问题描述】:
我正在开发一个自定义图库。某些图像的大小为 0Bytes ,我的图库不应允许大小等于 0 的图像。有没有办法找到图像的大小?或避免加载此类图像。 这是我的代码
Uri uri;
Cursor cursor;
int column_index_data;
long sizeIndex;
ArrayList<String> listOfAllImages = new ArrayList<>();
String absolutePathOfImage;
uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String[] projection = {MediaStore.MediaColumns.DATA,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME};
cursor = activity.getContentResolver().query(uri, projection, null,
null, MediaStore.MediaColumns.DATE_ADDED + " DESC");
if (cursor != null) {
column_index_data = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);
while (cursor.moveToNext()) {
if (sizeIndex != 0) {
Log.e("sizeimage", "" + sizeIndex);
absolutePathOfImage = cursor.getString(column_index_data);
listOfAllImages.add(absolutePathOfImage);
}
}
thumbnailsselection = new boolean[cursor.getCount()];
cursor.close();
}
PS 我不想在查找大小时将它们转换为位图。
【问题讨论】:
-
在您的
projection添加尺寸字段。
标签: java android size image-gallery