You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by "Bright Zheng (Created) (JIRA)" <ji...@apache.org> on 2011/11/08 08:34:53 UTC

[jira] [Created] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

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 Callback
          Issue Type: Improvement
          Components: Android
    Affects Versions: 1.1.0
         Environment: Android SDK: 2.x & above
JDK: 1.6
Eclipse: Helios
            Reporter: Bright Zheng
            Priority: Critical
             Fix For: 2.0.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

        

[jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Joe Bowser (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13273441#comment-13273441 ] 

Joe Bowser commented on CB-14:
------------------------------

@George: See CB-415 for your bug
                
> 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

        

[jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "George Hamilton (JIRA)" <ji...@apache.org>.
    [ 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

        

[jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Bright Zheng (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13201019#comment-13201019 ] 

Bright Zheng commented on CB-14:
--------------------------------

@Simon, my pleasure. I have sent out the CLA by following the procedures. Thanks.

Actually, I think you guys should review the related API usage on this project because I just patched what I used.
The coverage is NOT 100%. 
                
> 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 Callback
>          Issue Type: Improvement
>          Components: Android
>    Affects Versions: 1.1.0
>         Environment: Android SDK: 2.x & above
> JDK: 1.6
> Eclipse: Helios
>            Reporter: Bright Zheng
>            Priority: Critical
>              Labels: CameraLauncher, OutOfMemory, decodeStream
>             Fix For: 2.0.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

        

[jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Joe Bowser (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13260659#comment-13260659 ] 

Joe Bowser commented on CB-14:
------------------------------

@Christopher: If you have a patch, or at least a working code sample, by all means share it.  Please open a new ticket and describe what the code does.  If the patch is signficant enough, we may ask you to sign a CLA, but it'd save us a lot of time doing this instead of re-inventing the wheel.
                
> 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 Callback
>          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

        

[jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Joe Bowser (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13200219#comment-13200219 ] 

Joe Bowser commented on CB-14:
------------------------------

I tested the patch, and I managed to get the same thing as @PamelaFox.  However, when I use FILE_URI I don't have this issue at all, however this code isn't used either. I suspect that this is an issue with passing a large amount of data across an intent and manipulating it, which in my experience has always led to disaster.  We should probably discuss removing the DATA_URL option or re-thinking it in a later release.
                
> 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 Callback
>          Issue Type: Improvement
>          Components: Android
>    Affects Versions: 1.1.0
>         Environment: Android SDK: 2.x & above
> JDK: 1.6
> Eclipse: Helios
>            Reporter: Bright Zheng
>            Priority: Critical
>              Labels: CameraLauncher, OutOfMemory, decodeStream
>             Fix For: 2.0.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

        

[jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Joe Bowser (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13217766#comment-13217766 ] 

Joe Bowser commented on CB-14:
------------------------------

@Lucas I think you're right on this one, and I'm going to have to investigate this further.  We used to maintain our own Camera Activity and we dropped it because of the device fragmentation issues with Cameras and filters.  The solution may be that we have a camera plugin that is implemented separately from the core that people can use if they run into this issue, and we might just have to mitigate the DATA_URL issue.
                
> 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 Callback
>          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: 2.0.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

        

[jira] [Updated] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Joe Bowser (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Joe Bowser updated CB-14:
-------------------------

    Fix Version/s:     (was: 2.0.0)
                   1.6.0
    
> 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 Callback
>          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

        

[jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Joe Bowser (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13259908#comment-13259908 ] 

Joe Bowser commented on CB-14:
------------------------------

@Christopher OK, so if you are absolutely required to pass the image as a Base64 encoded stream from your camera API back to Cordova and you can't save your image any other way whatsoever (i.e. File URI), that's when I recommend creating your own Camera plugin.  Using DATA_URI for this is not recommended for many reasons, most of which involves the large amount of data that you are going to be passing through intents.  I don't believe that SaveInstanceState saves the state of the WebView, and that this is a red herring.

Simple Solution: Don't use DATA_URI for any large images
Complex Solution: If you MUST have Base64 data, write your own plugin because your requirements are unique.

That being said, I really have to try hard to reproduce this error with a DATA_URL on the Nexus S.
                
> 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 Callback
>          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

        

[jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Pamela Fox (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13199556#comment-13199556 ] 

Pamela Fox commented on CB-14:
------------------------------

@Joe Bowser: OK, I've filed https://issues.apache.org/jira/browse/CB-220
                
> 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 Callback
>          Issue Type: Improvement
>          Components: Android
>    Affects Versions: 1.1.0
>         Environment: Android SDK: 2.x & above
> JDK: 1.6
> Eclipse: Helios
>            Reporter: Bright Zheng
>            Priority: Critical
>              Labels: CameraLauncher, OutOfMemory, decodeStream
>             Fix For: 2.0.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

        

[jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Will Koper (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13451046#comment-13451046 ] 

Will Koper commented on CB-14:
------------------------------

I tried to implement Christopher's solution, but since the callback server hasn't started when I call setActivityResultForCallback, the pluginSuccess call gets lost in the ether. Same goes if I try to instantiate the callbackServer in my onCreate function because the cb server restarts itself.

Is it worth requesting that the devs implement a way to save and restore plugins from the savedInstanceState bundle?
                
> 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
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Christopher Bailey (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13259883#comment-13259883 ] 

Christopher Bailey commented on CB-14:
--------------------------------------

@Joe I too am facing the same issue. Asking people to implement their own camera solution for anyone needing to use the camera api is far from ideal. I think you could go some way to mitigating this issue if the cordova app saved it's application state (or rather that of it's plugins) using the onSaveInstanceState hook provided by Android:
http://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState(android.os.Bundle)
Cordova could then check the bundle in the onCreate method to recreate the relevant plugins and allow the intent to be passed back to the application (obviously it would still be up to application developers to maintain their own app's state using the js destroy/resume events).
                
> 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 Callback
>          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

        

[jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Simon MacDonald (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13199816#comment-13199816 ] 

Simon MacDonald commented on CB-14:
-----------------------------------

Bright, you code seems to help this issue. Can you sign the CLA:

http://www.apache.org/licenses/#clas

so we can add it to a future release?
                
> 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 Callback
>          Issue Type: Improvement
>          Components: Android
>    Affects Versions: 1.1.0
>         Environment: Android SDK: 2.x & above
> JDK: 1.6
> Eclipse: Helios
>            Reporter: Bright Zheng
>            Priority: Critical
>              Labels: CameraLauncher, OutOfMemory, decodeStream
>             Fix For: 2.0.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

        

[jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Pamela Fox (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13161938#comment-13161938 ] 

Pamela Fox commented on CB-14:
------------------------------

I added the suggested method to my Phonegap and it resolved the original OutOfMemory error, but I still experienced two other OutOfMemory errors:
"bitmap size exceeds VM budget" (full trace: http://pastebin.com/raw.php?i=0SsTgbvF)
And one during com.phonegap.api.PluginResult.toSuccessCallbackString (full trace: http://pastebin.com/raw.php?i=3cgyR5Dk)

I seem to avoid these issues by requesting a low quality (20) and low width/height (400/400)..but I imagine that workaround won't work for all people using the Camera API, and I don't feel great on relying on that as a solution.

                
> 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 Callback
>          Issue Type: Improvement
>          Components: Android
>    Affects Versions: 1.1.0
>         Environment: Android SDK: 2.x & above
> JDK: 1.6
> Eclipse: Helios
>            Reporter: Bright Zheng
>            Priority: Critical
>              Labels: CameraLauncher, OutOfMemory, decodeStream
>             Fix For: 2.0.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

        

[jira] [Assigned] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Joe Bowser (Assigned) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Joe Bowser reassigned CB-14:
----------------------------

    Assignee: Joe Bowser
    
> 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 Callback
>          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: 2.0.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

        

[jira] [Resolved] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Joe Bowser (Resolved) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Joe Bowser resolved CB-14.
--------------------------

    Resolution: Not A Problem

I recommend that people who NEED a Camera work on a Camera Plugin and concentrate on maintaining that, since that is currently beyond our scope.
                
> 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 Callback
>          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

        

[jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Christopher Bailey (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13264905#comment-13264905 ] 

Christopher Bailey commented on CB-14:
--------------------------------------

It's not much code and I'm only interested in the situation where the app was destroyed after firing up the camera/album app. I'm sure it's easy to extend for other plugins.
Firstly I override CameraLauncher.java just to make public the private vars. I call this CustomCameraPlugin

Then in my activity I add the following:
{noformat}
public void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstanceState);
	if (savedInstanceState == null || savedInstanceState.isEmpty())
	{
		super.setIntegerProperty("splashscreen", R.drawable.startup);
		super.loadUrl("file:///android_asset/www/index.html", 2000);
	}
	else
	{
		String sCallback = savedInstanceState.getString("callback");
		if (sCallback != null)
		{
			try
			{
				if (sCallback.equals(CustomCameraPlugin.class.toString()))
				{
					CustomCameraPlugin c = new CustomCameraPlugin();
					c.callbackId = savedInstanceState.getString("callbackId");
					c.setContext(this);
					c.setView(this.appView);
					String uri = savedInstanceState.getString("imageUri");
					if (uri != null)
					{
						c.imageUri = Uri.fromFile(new File(uri));
					}
					c.mediaType = savedInstanceState.getInt("mediaType");
					c.targetHeight = savedInstanceState.getInt("targetHeight");
					c.targetWidth = savedInstanceState.getInt("targetWidth");
					setActivityResultCallback(c);
				}
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
		}
		// add a hash to the url to indicate we need to add the custom callback
		super.loadUrl("file:///android_asset/www/index.html#new");
	}
}

@Override
public void onSaveInstanceState(Bundle savedInstanceState)
{
	IPlugin callback = (IPlugin) this.activityResultCallback;
	if (callback != null)
	{
		String className = callback.getClass().toString();
		savedInstanceState.putString("callback", className);

		if (className.equals(CustomCameraPlugin.class.toString()))
		{
			CustomCameraPlugin c = (CustomCameraPlugin) callback;);

			savedInstanceState.putString("callbackId", "Camera");
			if (c.imageUri != null)
				savedInstanceState.putString("imageUri", c.imageUri.getPath());
			savedInstanceState.putInt("mediaType", c.mediaType);
			savedInstanceState.putInt("targetHeight", c.targetHeight);
			savedInstanceState.putInt("targetWidth", c.targetWidth);
		}
	}
	super.onSaveInstanceState(savedInstanceState);
}
{noformat}

Finally in the webview, I add the following to pick up the modified callback:
{noformat}
if (window.location.hash) {
	log("Location hash exists ... setting callback");
	if (typeof cordova !== "undefined") {
		cordova.callbacks["Camera"] = {
			success : savePicUri,
			fail : unableToTakePhoto
		};
	} else {
		log("  ... callback setting failed. Cordova undefined.");
	}
}
{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 Callback
>          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

        

[jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Joe Bowser (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13198120#comment-13198120 ] 

Joe Bowser commented on CB-14:
------------------------------

Is this meant to be a patch?  I see that it's been assigned to 2.0.0 for a fix.

@Pamela Fox: Can you write a ticket indicating what device you ran into this on?  I've run into this on very low-end Android devices.
                
> 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 Callback
>          Issue Type: Improvement
>          Components: Android
>    Affects Versions: 1.1.0
>         Environment: Android SDK: 2.x & above
> JDK: 1.6
> Eclipse: Helios
>            Reporter: Bright Zheng
>            Priority: Critical
>              Labels: CameraLauncher, OutOfMemory, decodeStream
>             Fix For: 2.0.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

        

[jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Ben Plowman (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13147202#comment-13147202 ] 

Ben Plowman commented on CB-14:
-------------------------------

Definitely agree that this is important. I have found lots of OOM errors in strange places on Android before I started scaling bitmaps like this.
                
> 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 Callback
>          Issue Type: Improvement
>          Components: Android
>    Affects Versions: 1.1.0
>         Environment: Android SDK: 2.x & above
> JDK: 1.6
> Eclipse: Helios
>            Reporter: Bright Zheng
>            Priority: Critical
>              Labels: CameraLauncher, OutOfMemory, decodeStream
>             Fix For: 2.0.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

        

[jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Lucas Emanuel Martins Farias (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13215021#comment-13215021 ] 

Lucas Emanuel Martins Farias commented on CB-14:
------------------------------------------------

This problem occurs when your application is sent to background and the camera activity is in the foreground. We discovered that our application is being killed because camera takes too much memory and the garbage colector release memory killing background apps. This problem occurs with native Android apps too, so you have to build your own camera app. We resolved this problem creating our camera app described here: http://developer.android.com/guide/topics/media/camera.html#custom-camera 
So we created a Camera Activity that is called by a plugin and the problem donĀ“t occured anymore. This way, you app is in foreground preventing the GC to kill it.


                
> 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 Callback
>          Issue Type: Improvement
>          Components: Android
>    Affects Versions: 1.1.0
>         Environment: Android SDK: 2.x & above
> JDK: 1.6
> Eclipse: Helios
>            Reporter: Bright Zheng
>            Priority: Critical
>              Labels: CameraLauncher, OutOfMemory, decodeStream
>             Fix For: 2.0.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

       

[jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Christopher Bailey (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13260447#comment-13260447 ] 

Christopher Bailey commented on CB-14:
--------------------------------------

@Joe. Sorry I think my confusion was due to the incorrect assignment of issue CB-193 being merged into this ticket. Essentially when Cordova or any app fires up the camera (regardless of FILE_URI or DATA_URL) then the OS can decide summarily to kill of the app as it's running in the background. This is the issue mentioned in CB-193. You can try this yourself by firing up the camera and then using the task switcher/home key to change to one or more memory intensive apps (e.g. browser)

This issue was particularly prevalent with the camera app on my Galaxy S so I have implemented a workaround by extending CameraLauncher and saving it's state in my Activity's onSaveInstanceState(). I feel that DroidGap.java should be doing this itself so that it can recover from such an event.
                
> 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 Callback
>          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

        

[jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions

Posted by "Bright Zheng (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13273144#comment-13273144 ] 

Bright Zheng commented on CB-14:
--------------------------------

Hi George,

Maybe the definition of status & resolution is not accurate since the issue is still there.

They just want to put this as scope of plugin which the users/developers have to cope with.

My suggestion to you is to follow my steps as above mentioned and you can go more far.

Good luck!
Bright
                
> 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