2013-07-25 2 views
0

나는 사용자가 외부 저장에서 비트 맵을 얻기 위해이 코드를안드로이드 : 스트림 디코드 비트 맵

/** 
* Get bitmap from input stream 
* @param is 
* @param reqWidth 
* @param reqHeight 
* @return Bitmap 
*/ 
public static Bitmap decodeSampleBitmapFromStream(InputStream is, int reqWidth, 
     int reqHeight) { 

    BufferedInputStream bis = new BufferedInputStream(is); 

    // First decode with inJustDecodeBounds=true to check dimensions 
    final BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inJustDecodeBounds = true; 
    BitmapFactory.decodeStream(bis, null, options); 

    // Calculate inSampleSize 
    options.inSampleSize = calculateInSampleSize(options, reqWidth, 
      reqHeight); 

    try { 
     bis.reset(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

    // Decode bitmap with inSampleSize set 
    options.inJustDecodeBounds = false; 
    return BitmapFactory.decodeStream(bis, null, options); 
} 

가 지원의 대부분에서 잘 작동하지만 일부에 나는이 경고를

07-23 21:06:32.355: D/PowerManagerService(2687): onSensorChanged: light value: 10 
07-23 21:06:32.510: W/System.err(26270): java.io.IOException: Mark has been invalidated. 
07-23 21:06:32.510: W/System.err(26270):   at java.io.BufferedInputStream.reset(BufferedInputStream.java:371) 
07-23 21:06:32.510: W/System.err(26270):   at ant.fileExplorer.FileExplorerAdapter.decodeSampleBitmapFromStream(FileExplorerAdapter.java:168) 

이 있습니다 이 부분에 대한 내용입니다

try { 
     bis.reset(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

그리고 나는 실제로 이해할 수 없습니다. 당신의 도움이

+0

을 비트 맵을 얻기 위해 위의 정적 메소드를 사용 뭔가 안좋은 것... – TN888

답변

1
public static Bitmap decodeSampleBitmapFromFile(String filePath, int reqWidth, 
     int reqHeight) { 

    // First decode with inJustDecodeBounds=true to check dimensions 
    final BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inJustDecodeBounds = true; 
    BitmapFactory.decodeFile(filePath,options); 

    // Calculate inSampleSize 
    options.inSampleSize = calculateInSampleSize(options, reqWidth,reqHeight); 

    // Decode bitmap with inSampleSize set 
    options.inJustDecodeBounds = false; 
    return BitmapFactory.decodeFile(filePath,options); 
} 

에 대한

덕분에 내가 경고가 아니라고 생각 제대로 ..... 외부 저장

파일 경로를 부여에서