我需要获取在输入流中找到的图像的高度和宽度。这是我所做的:
private Boolean testSize(InputStream inputStream){
BitmapFactory.Options Bitmp_Options = new BitmapFactory.Options();
Bitmp_Options.inJustDecodeBounds = true;
BitmapFactory.decodeResourceStream(getResources(), new TypedValue(), inputStream, new Rect(), Bitmp_Options);
int currentImageHeight = Bitmp_Options.outHeight;
int currentImageWidth = Bitmp_Options.outWidth;
Bitmp_Options.inJustDecodeBounds = false;
if(currentImageHeight < 200 || currentImageWidth < 200){
Object obj = map.remove(pageCounter);
Log.i("Page recycled", obj.toString());
return true;
}
return false;}
跳到问题点:
即使我在下面的第二种方法计算后强制它为假,它也会改变 BitmapFactory.Options。
private Bitmap getBitmap(InputStream InpStream){
Bitmap originalBitmap = BitmapFactory.decodeStream(InpStream);//Null.
return originalBitmap;
}
现在我的问题是有另一种从输入流中获取图像大小和宽度的方法吗?我真的需要帮助,非常感谢任何帮助。
ZipInputStream zip = null;
zip = new ZipInputStream(new FileInputStream(getFileLocation()));
for(ZipEntry zip_e = zip.getNextEntry(); zip_e != null ; zip_e = zip.getNextEntry()){
if(zip_e.isDirectory()) {
continue;
}
String file_zip = zip_e.getName();
String comparison = map.get(pageCounter).getHref();
if(file_zip.endsWith(comparison)){
SpannableString Spanable_String = new SpannableString("abc");
if(testSize(zip)){
map.remove(pageCounter);
return false;
}
Bitmap bitmap = getBitmap(zip);
if(bitmap == null){
map.remove(pageCounter);
return false;
}
image_page.put(zip_e.getName(), zip);
Drawable drawable_image = new FastBitmapDrawable(bitmap);
drawable_image.setBounds(0,0,drawable_image.getIntrinsicWidth(), drawable_image.getIntrinsicHeight());
ImageSpan imageSpan = new ImageSpan(drawable_image, ImageSpan.ALIGN_BASELINE);
Spanable_String.setSpan(imageSpan, 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(Spanable_String);
return false;
}
}