InputStream is = null;
try {
Uri imgUri = new Uri.Builder().build().parse(uri);
is = getContentResolver().openInputStream(imgUri);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BitmapFactory.Options bounds = new BitmapFactory.Options();
bounds.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is, null, bounds);
if (bounds.outWidth == -1) {
Log.d("load image", "fail");
}// TODO: Error }
int width = bounds.outWidth;
boolean isTooBig = width > (int) maxSize;
if (isTooBig) {
int scale = (int) (width / maxSize);
BitmapFactory.Options resample = new BitmapFactory.Options();
resample.inSampleSize = scale;
imageBmp = BitmapFactory.decodeStream(is, null, resample);
} else {
imageBmp = BitmapFactory.decodeStream(is);
}
if (imageBmp.getWidth() > maxSize) {
int w = (int) maxSize;
float ratio = w / (float) (imageBmp.getWidth());
int h = (int) (ratio * imageBmp.getHeight());
imageBmp = Bitmap.createScaledBitmap(imageBmp, w, h, true);
}
이런식으로 inputstream 가져다가 이미지를 얻으려고 하는데... 계속 이미지가 null로 들어오길래 확인해 봤더니
InputStream 으로 선언한 is를 한번 사용하면 상관이 없는데 위에서 decodestream하면서 사용하고 다시 한번 decodestream에서 사용하면
이미지가 널이 됩니다..-ㅅ-;; InputStream는 한번만 사용이 가능한가요...?