ContentResolver cr = context.getContentResolver();
Uri image_uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Cursor cursor = cr.query(image_uri, null,
MediaStore.MediaColumns.DATA +" = '"+ imagePath +"'" , null, null);
if (cursor == null) {
return null;
}
cursor.moveToFirst();
if (cursor.getCount() == 0) return null;
try {
long idValue = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns._ID));
Bitmap bmp = MediaStore.Images.Thumbnails.getThumbnail(cr, idValue,
MediaStore.Images.Thumbnails.MINI_KIND, null); //MICRO_KINDだと正方形が返ってくるので不便極まりない
return bmp;
} catch (IllegalArgumentException e) {
e.printStackTrace();
return null;
}catch (CursorIndexOutOfBoundsException e) {
e.printStackTrace();
return null;
} finally {
cursor.close();
}
ContentResolverで画像を取り出す
取り出すだけなら以下でできると思う
コメント