2012-07-31 4 views
1

내가 썸네일 크기로 SD 카드에서 선택된 사진의 크기를 조정하기 위해 노력하고 크기를 조정하지만 난 내 기본 이미지의 크기로, 크기를 조정할 때 128/128 비트 맵이 null 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 비트 맵을 반환합니다.

리소스 파일로이 방법을 사용했지만 결코 SD 카드의 이미지로 Uri을 사용하지 않았습니다. 내가 뭘 잘못하고있는 걸까요?

답변

0

동일한 입력 스트림을 두 번 사용할 수 없으므로 두 번째로 새 InputStream을 만들어야합니다. 자세한 내용은 here을 참조하십시오.

+0

아, 그 이유를 알지 못했습니다. – tyczj