I need to get the height and width of the image found in the inputstream. Here is what I did:
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;}
Skipping to the problem at point:
It change BitmapFactory.Options even if I forced it to be false after calculation on my second method below.
private Bitmap getBitmap(InputStream InpStream){
Bitmap originalBitmap = BitmapFactory.decodeStream(InpStream);//Null.
return originalBitmap;
}
Now to my question is there another way of getting the size and width of an image from an inputstream? I really need help on this any help is greatly appreciated.
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;
}
}
BitmapFactory.decodeStream()
? – Unvalued