rokkonet

PC・Androidソフトウェア・アプリの開発・使い方に関するメモ

android開発 画像UriからBitmap画像を取得する

2020 Mar. 21.

InputStream inStreamImage;
Uri imageUri;
Bitmap smallBmp;

// 画像uriをInputStreamにする
try {
    inStreamImage = this.getApplicationContext().getContentResolver().openInputStream(imageUri);
} catch (FileNotFoundException e) {
}
        
/*
    * 画像インプットストリームを 1/SCALE に縮小したbitmapにする
        https://qiita.com/exilias/items/38075e08ca45d223cf92 を参考にした
*/
final int SCALE = 4;
BitmapFactory.Options imageOptions = new BitmapFactory.Options();
imageOptions.inSampleSize = SCALE;
try {
    smallBmp = BitmapFactory.decodeStream(inStreamImage, null, imageOptions);
} finally {
}