Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8138361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:28:08+00:00 2026-06-06T11:28:08+00:00

I need to get the height and width of the image found in the

  • 0

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;
                    }
                }   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:28:10+00:00Added an answer on June 6, 2026 at 11:28 am

    The main problem is not with the BitmapFactory.Options, but with the InputStream. The stream is sequential, therefore when you read the stream to decode the image for size only, the pointer in the stream is moving. Next, when you’re calling decode again to actually decode the bitmap, the stream pointer is no longer at the beginning of the bitmap, and you get null because the partial stream cannot be decode.

    You would need to reset the stream. Depending on what that stream is, you might be able to use .mark and .reset on it. Essentially, you’d do something like this:

    private Boolean testSize(InputStream inputStream) {
        BitmapFactory.Options Bitmp_Options = new BitmapFactory.Options();
        Bitmp_Options.inJustDecodeBounds = true;
    
        inputStream.mark(inputSteram.available());
    
        BitmapFactory.decodeResourceStream(getResources(), new TypedValue(), inputStream, new Rect(), Bitmp_Options);
    
        inputSteram.reset();
    
        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;
    }
    

    You can check whether your InputStream supports this or not by calling markSupported on it. If that returns true then you can use the above technique. If it returns false, then the above method will not work and you will actually need to close and reopen the stream again before decoding the full bitmap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get the actual width and height of the shareddiv before populating
I want to get image height and width when it is not set from
How to get an uploaded image's height and width before form submission , using
I need to scale down an image that has a height or width greater
I need to get the Width and Height of a img tag, when it's
I need to get height of an element that is within a div that
I need to get the height from top of the page to current scrollbar
I need to get the full height of a UITableView (i.e. the height at
I need a function to get the height of the highest element inside a
I need help for get my layout of a image and text to work.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.