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();
    }

而且我真的不明白不能执行。

谢谢你的帮助

4

1 回答 1

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);
}

使用上述静态方法从外部存储中获取位图

正确给出filePath .....

于 2013-07-25T08:27:06.780 回答