SDカードから選択した画像のサイズをサムネイルサイズに変更しようとしていますが、サイズを変更すると、デフォルトの画像128/128
のサイズに合わせてビットマップがnullになります
InputStream input=null;
try {
input = getActivity().getContentResolver().openInputStream(Uri.parse(cursor.getString(3)));
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(input, null, options);
int height = options.outHeight; //1030
int width = options.outWidth; //1033
BitmapFactory.decodeResource(getResources(), R.drawable.ic_contact_picture, options);
int imageHeight = options.outHeight; //128
int imageWidth = options.outWidth; //128
if(imageWidth > imageHeight){
options.inSampleSize = Math.round((float)height/(float)imageHeight);
}else{
options.inSampleSize = Math.round((float)width/(float)imageWidth);
}
options.inJustDecodeBounds = false;
Bitmap bm = BitmapFactory.decodeStream(input,null, options); //null here
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
image.setImageBitmap(bm);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
画像の高さと幅の両方を取得できますが、サイズを変更すると、nullビットマップが返されます。
私はリソースファイルを使ってこのようにしたがUri
、SDカードからの画像を使ったことがないので、何が間違っているのですか?