The 750,000 bytes are the size of the *compressed* JPEG.
A Bitmap instance holds the *raw* color data, not the compressed data.

E.g. if the raw color data has format ARGB_8888, then each pixel uses
4 bytes: 5MPixel images will use 20MBytes of memory. If the raw color
data has the format RGB_565, then each pixes uses 2 bytes: 5MPixel
images will use 10MBytes of memory. This is what you see.

To load the image for viewing, you don't need more than the screen-
resolution. Use the inSampleSize of the BitmapFractory.Options; set it
to a number larger than 1 (preferably a power of 2).


On Apr 15, 5:53 pm, John <[email protected]> wrote:
> After I've used a MediaStore.ACTION_IMAGE_CAPTURE intent to take a
> photo, when I try to retrieve the captured image, I sometimes get an
> out of memory error as shown below.   The odd thing is the huge size
> of the memory trying to be allocated is always reported as 10,077,696
> (x99c600).   However, the image file is much smaller, typically around
> 750,000 bytes.    Any suggestions on how to get around this problem?
> I'm testing this on a Nexus One with firmware  version:  2.1-update1
> and Build number: ERE27.
>
> ----- logcat output --------------------
>
> D/photo   ( 5562):   photoUri=content://media/external/images/media/32
> E/dalvikvm-heap( 5562): 10077696-byte external allocation too large
> for this process.
> E/        ( 5562): VM won't let us allocate 10077696 bytes
> D/skia    ( 5562): --- decoder->decode returned false
>
> W/System.err( 5562): java.lang.OutOfMemoryError: bitmap size exceeds
> VM budget
> W/System.err( 5562):    at
> android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
> W/System.err( 5562):    at
> android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:459)
> W/System.err( 5562):    at
> android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:515)
> W/System.err( 5562):    at android.provider.MediaStore$Images
> $Media.getBitmap(MediaStore.java:475)
>
> ---- code used to start the camera -----------------------
>
>         Intent photoPickerIntent = new
> Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
>         Uri photoUri = getNewTempPhotoUri();
>         photoPickerIntent.putExtra( MediaStore.EXTRA_OUTPUT,
> photoUri );
>         photoPickerIntent.putExtra( MediaStore.EXTRA_VIDEO_QUALITY,
> "0") ; // 0= low quality suitable for MMS
>         photoPickerIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
>         activity.startActivityForResult(photoPickerIntent,
> WimgoApplication.ADD_PHOTO );
>
>         private  Uri getNewTempPhotoUri() {
>             ContentValues values = new ContentValues();
>             values.put(Media.TITLE, "a title");
>             values.put(Media.DESCRIPTION, "a description");
>             tempPhotoUri = null;
>             try {
>                 tempPhotoUri =
> getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
>             } catch(UnsupportedOperationException e){
>                 try{
>                     tempPhotoUri =
> getContentResolver().insert(Media.INTERNAL_CONTENT_URI, values);
>                 }catch(UnsupportedOperationException e2){
>                     e2.printStackTrace();
>                 }
>             }
>             return tempPhotoUri ;
>         }
>
> -----  code called from my onActivityResult method used to retrieve
> the image --------------------
>
>         Bitmap bitmap =
> MediaStore.Images.Media.getBitmap(getContentResolver(),
> tempPhotoUri );
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to