Mark已失效错误

时间:2014-03-27 10:20:02

标签: android bitmap bitmapfactory

我阅读了关于有效加载大位图的android开发指南。这里有一些代码来解释我在做什么。

fis = imageToSend.getReadStream();
InputStream is = new BufferedInputStream(fis);                          
bitmapToSend = decodeSampleBitmapFromStream(is, 60, 60);
.
.
.
public Bitmap decodeSampleBitmapFromStream(InputStream is, int reqWidth, int reqHeight){
      // First decode with inJustDecodeBounds=true to check dimensions
      final BitmapFactory.Options options = new BitmapFactory.Options();
      options.inJustDecodeBounds = true;
      BitmapFactory.decodeStream(is,null,options);

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

      // Decode bitmap with inSampleSize set
      options.inJustDecodeBounds = false;
      try {
        is.reset();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
      return  BitmapFactory.decodeStream(is,null,options);
}

public static int calculateInSampleSize(
        BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;

if (height > reqHeight || width > reqWidth) {

    final int halfHeight = height / 2;
    final int halfWidth = width / 2;

    // Calculate the largest inSampleSize value that is a power of 2 and keeps both
    // height and width larger than the requested height and width.
    while ((halfHeight / inSampleSize) > reqHeight
            && (halfWidth / inSampleSize) > reqWidth) {
        inSampleSize *= 2;
    }
}

return inSampleSize;
}

我试图通过将inJustDecodeBounds设置为true来解码fis,然后计算样本大小但是它返回IOException:Mark已经失效。有人可以解释这个错误是什么以及如何修复它?

0 个答案:

没有答案