How to get bitmap infomation before decode an image file?

Showing 1-3 of 3 messages
How to get bitmap infomation before decode an image file? quill 6/4/09 1:37 AM
Hi all,
I want to know an image's width before decode it, so that I can set
Options.inSampleSize if the image is too large. Any advice to do that?
Re: How to get bitmap infomation before decode an image file? Streets Of Boston 6/4/09 7:08 AM
Set the Options.inJustDecodeBounds to true and call the
BitmapFactory's method to get/decode your bitmap. The bitmap returned
will be null, but the Options.outWidth and Options.outHeight will be
set to the image's width and height in pixels.


Then call the BitmapFactory's method to get/decode your bitmap again,
with Options.inJustDecodeBounds set to false and its inSampleSize set
to your liking.

BTW: This is all in the documentation:
http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inJustDecodeBounds
Re: How to get bitmap infomation before decode an image file? quill 6/4/09 6:55 PM
Is there any limit to use  inJustDecodeBounds? When my picture is
small enough, it works well, but it will report "failed binder
transaction" in logcat when the picture size is larger than 100k. I
have not use any binder, and it works well even the bitmap size is 1M
before using Options argument.
Here's my code:

Options opts = new Options();
                opts.inJustDecodeBounds = true;
                BitmapFactory.decodeFile(path, opts);
                Log.e("optwidth",opts.outWidth+"");
                opts.inJustDecodeBounds = false;
                if(opts.outWidth>500){
                        opts.inSampleSize = 4;
                        mBitmap = BitmapFactory.decodeFile(path, opts);
                }
                else mBitmap = BitmapFactory.decodeFile(path, opts);

On Jun 4, 10:08 pm, Streets Of Boston <flyingdutc...@gmail.com> wrote:
> Set the Options.inJustDecodeBounds to true and call the
> BitmapFactory's method to get/decode your bitmap. The bitmap returned
> will be null, but the Options.outWidth and Options.outHeight will be
> set to the image's width and height in pixels.
>
> Then call the BitmapFactory's method to get/decode your bitmap again,
> with Options.inJustDecodeBounds set to false and its inSampleSize set
> to your liking.
>
> BTW: This is all in the documentation:http://developer.android.com/reference/android/graphics/BitmapFactory...
>
> On Jun 4, 4:37 am, quill <quill...@163.com> wrote:
>
>
>
> > Hi all,
> > I want to know an image's width before decode it, so that I can set
> > Options.inSampleSize if the image is too large. Any advice to do that?- Hide quoted text -
>
> - Show quoted text -