Android 标记因错误而无效
我阅读了android开发指南中关于高效加载大型位图的内容。下面是一些代码来解释我在做什么Android 标记因错误而无效,android,bitmap,bitmapfactory,Android,Bitmap,Bitmapfactory,我阅读了android开发指南中关于高效加载大型位图的内容。下面是一些代码来解释我在做什么 fis = imageToSend.getReadStream(); InputStream is = new BufferedInputStream(fis); bitmapToSend = decodeSampleBitmapFromStream(is, 60, 60); . . . public Bitmap decodeSampleBitmapF
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:标记已无效。有人能解释一下这个错误是什么以及如何修复它吗?你是对所有图像还是对某些图像都这样做?我对所有图像都这样做,所有这些都是相同的解决方案OK..等等,我会发布..发布我的代码..像那样更改并让我知道。。