incubator-callback-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "George Hamilton (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions
Date Fri, 11 May 2012 09:31:54 GMT

    [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13273136#comment-13273136
] 

George Hamilton commented on CB-14:
-----------------------------------

Hi

I notice this issue status is 'Resolved' and resolution 'Not A Problem'.  With my Asus Transformer
using phonegap 1.7.0, the camera is crashing the application when the picture size is set
to 8M.  I am using FILE_URI.  Here is my code:

{noformat}
navigator.camera.getPicture(
    function(fileURI){
        console.log(fileURI);
    },
    function(message){
        console.log(message);
    },
    {
        quality: 50,
        destinationType: Camera.DestinationType.FILE_URI,
        sourceType : Camera.PictureSourceType.CAMERA
    }
);
{noformat}

and the exception:

{noformat}
D/dalvikvm(23824): GC_FOR_ALLOC freed 275K, 81% free 7792K/39239K, paused 33ms
I/dalvikvm-heap(23824): Forcing collection of SoftReferences for 31961104-byte allocation
D/dalvikvm(23824): GC_BEFORE_OOM freed 28K, 81% free 7764K/39239K, paused 22ms
E/dalvikvm-heap(23824): Out of memory on a 31961104-byte allocation.
I/dalvikvm(23824): "main" prio=5 tid=1 RUNNABLE
I/dalvikvm(23824):   | group="main" sCount=0 dsCount=0 obj=0x40a39460 self=0x3f2828
I/dalvikvm(23824):   | sysTid=23824 nice=0 sched=0/0 cgrp=default handle=1074562184
I/dalvikvm(23824):   | schedstat=( 18895478000 6928031000 33348 ) utm=1662 stm=227 core=0
I/dalvikvm(23824):   at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
I/dalvikvm(23824):   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493)
I/dalvikvm(23824):   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:549)
I/dalvikvm(23824):   at android.provider.MediaStore$Images$Media.getBitmap(MediaStore.java:716)
I/dalvikvm(23824):   at org.apache.cordova.CameraLauncher.onActivityResult(CameraLauncher.java:296)
I/dalvikvm(23824):   at org.apache.cordova.DroidGap.onActivityResult(DroidGap.java:1145)
I/dalvikvm(23824):   at android.app.Activity.dispatchActivityResult(Activity.java:4649)
I/dalvikvm(23824):   at android.app.ActivityThread.deliverResults(ActivityThread.java:2976)
I/dalvikvm(23824):   at android.app.ActivityThread.handleSendResult(ActivityThread.java:3023)
I/dalvikvm(23824):   at android.app.ActivityThread.access$1100(ActivityThread.java:123)
I/dalvikvm(23824):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1177)
I/dalvikvm(23824):   at android.os.Handler.dispatchMessage(Handler.java:99)
I/dalvikvm(23824):   at android.os.Looper.loop(Looper.java:137)
I/dalvikvm(23824):   at android.app.ActivityThread.main(ActivityThread.java:4424)
I/dalvikvm(23824):   at java.lang.reflect.Method.invokeNative(Native Method)
I/dalvikvm(23824):   at java.lang.reflect.Method.invoke(Method.java:511)
I/dalvikvm(23824):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
I/dalvikvm(23824):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
I/dalvikvm(23824):   at dalvik.system.NativeStart.main(Native Method)
I/dalvikvm(23824): 
D/skia    (23824): --- decoder->decode returned false
D/AndroidRuntime(23824): Shutting down VM
W/dalvikvm(23824): threadid=1: thread exiting with uncaught exception (group=0x40a381f8)
E/AndroidRuntime(23824): FATAL EXCEPTION: main
E/AndroidRuntime(23824): java.lang.OutOfMemoryError
E/AndroidRuntime(23824): 	at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
E/AndroidRuntime(23824): 	at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493)
E/AndroidRuntime(23824): 	at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:549)
E/AndroidRuntime(23824): 	at android.provider.MediaStore$Images$Media.getBitmap(MediaStore.java:716)
E/AndroidRuntime(23824): 	at org.apache.cordova.CameraLauncher.onActivityResult(CameraLauncher.java:296)
E/AndroidRuntime(23824): 	at org.apache.cordova.DroidGap.onActivityResult(DroidGap.java:1145)
E/AndroidRuntime(23824): 	at android.app.Activity.dispatchActivityResult(Activity.java:4649)
E/AndroidRuntime(23824): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:2976)
E/AndroidRuntime(23824): 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:3023)
E/AndroidRuntime(23824): 	at android.app.ActivityThread.access$1100(ActivityThread.java:123)
E/AndroidRuntime(23824): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1177)
E/AndroidRuntime(23824): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(23824): 	at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(23824): 	at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime(23824): 	at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(23824): 	at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(23824): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(23824): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(23824): 	at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager(  200):   Force finishing activity uk.ac.edina.mobile/.AndroidMapper
W/ActivityManager(  200): Activity pause timeout for ActivityRecord{415e7bf8 uk.ac.edina.mobile/.AndroidMapper}
D/WindowManager(  200): adjustConfigurationLw, config:{1.0 0mcc0mnc (no locale) layoutdir=0
sw800dp w1280dp h752dp xlrg land ?uimode ?night finger -keyb/v/h -nav/v} mLidOpen:-1 mHasDockFeature:true
mHasHallSensorFeature:true config.hardKeyboardHidden:2
{noformat}
                
> CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions
> ---------------------------------------------------------------------------------------------
>
>                 Key: CB-14
>                 URL: https://issues.apache.org/jira/browse/CB-14
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: Android
>    Affects Versions: 1.1.0
>         Environment: Android SDK: 2.x & above
> JDK: 1.6
> Eclipse: Helios
>            Reporter: Bright Zheng
>            Assignee: Joe Bowser
>            Priority: Critical
>              Labels: CameraLauncher, OutOfMemory, decodeStream
>             Fix For: 1.6.0
>
>
> Currently the CameraLauncher plugin of Phonegap (or Apache Callback) is using Android
default API for stream decoding.
> It will be very easy to get crash by throwing out the OutOfMemory exceptions while loading
bigger image files.
> So I add a new method called safeDecodeStream for better stream decoding.
> {code:title=safeDecodeStream method|borderStyle=solid}
>     /**
>      * A safer decodeStream method
>      * rather than the one of {@link BitmapFactory}
>      * which will be easy to get OutOfMemory Exception
>      * while loading a big image file.
>      * 
>      * @param uri
>      * @param width
>      * @param height
>      * @return
>      * @throws FileNotFoundException
>      */
>     protected Bitmap safeDecodeStream(Uri uri, int width, int height)
>     throws FileNotFoundException{
> 		int scale = 1;
> 		BitmapFactory.Options options = new BitmapFactory.Options();
> 		android.content.ContentResolver resolver = this.ctx.getContentResolver();
> 		
> 		if(width>0 || height>0){
> 			// Decode image size without loading all data into memory
> 			options.inJustDecodeBounds = true;
> 			BitmapFactory.decodeStream(
> 					new BufferedInputStream(resolver.openInputStream(uri), 16*1024),
> 					null,
> 					options);
> 			
> 			int w = options.outWidth;
> 			int h = options.outHeight;
> 			while (true) {
> 				if ((width>0 && w/2 < width)
> 						|| (height>0 && h/2 < height)){
> 					break;
> 				}
> 				w /= 2;
> 				h /= 2;
> 				scale *= 2;
> 			}
> 		}
> 		// Decode with inSampleSize option
> 		options.inJustDecodeBounds = false;
> 		options.inSampleSize = scale;
> 		return BitmapFactory.decodeStream(
> 				new BufferedInputStream(resolver.openInputStream(uri), 16*1024), 
> 				null, 
> 				options);
> 	}  
> {code} 
> And then change all the codes which are invoking the Android decodeStream API directly
to this method.
> e.g.
> {code:title=usage example|borderStyle=solid}
> //Updated by Bright for safer decodeStream
> //android.content.ContentResolver resolver = this.ctx.getContentResolver();
> //bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
> bitmap = safeDecodeStream(uri, this.targetWidth, this.targetHeight);
> {code} 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message