NativeScript / nativescript-camera

NativeScript plugin to empower using device camera.
Apache License 2.0
93 stars 46 forks source link

Incorrect image orientation and memory leak on Android / Galaxy S4 #58

Closed timostuebing closed 7 years ago

timostuebing commented 7 years ago

Please, provide the details below

camera-plugin ignores image-rotation after some pictures and then, when taking more images, makes the app crash with a memory error.

Did you verify this is a real problem by searching [Stack Overflow]

Yes.

Tell us about the problem

I have a view that takes pictures for being saved as part of a note.

In the beginnung, on my Samsung Galaxy S4, the images taken are rotated correctly. But after two or three pictures or so, it starts to ignore the orientation which results in portrait pictures being rotated by 90° CW. After that, all subsequent pictures are not rotated anymore.

Worse, this seems to go along with a memory leak, because after some more (incorrectly rotated) pictures the app crashes with

JS: ERROR Error: Uncaught (in promise): Error: java.lang.OutOfMemoryError: Failed to allocate a 600636 byte allocation with 148804 free bytes and 145KB until OOM
JS:     dalvik.system.VMRuntime.newNonMovableArray(Native Method)
JS:     android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
JS:     android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
JS:     android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:728)
JS:     android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:477)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:912)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:896)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:888)
JS:     com.tns.NativeScriptActivity.onActivityResult(NativeScriptActivity.java:69)
JS:     android.app.Activity.dispatchActivityResult(Activity.java:6549)
JS:     android.app.ActivityThread.deliverResults(ActivityThread.java:4063)
JS:     android.app.ActivityThread.handleSendResult(ActivityThread.java:4110)
JS:     android.app.ActivityThread.access$1400(ActivityThread.java:177)
JS:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1498)
JS:     android.os.Handler.dispatchMessage(Handler.java:102)
JS:     android.os.Looper.loop(Looper.java:145)
JS:     android.app.ActivityThread.main(ActivityThread.java:5951)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     java.lang.reflect.Method.invoke(Method.java:372)
JS:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
JS:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)

Other fellows had similar problems with the Cordova Camera Plugin. Unfortunately their solution relies on a setting called AllowEdit which nativescript-camera does not have. https://forum.ionicframework.com/t/camera-wrong-orientation-with-android/8583/25

I went into the nativescript-camera.android.js and put some logging there to eventually find the memory leak. What I found is the following behaviour:

First picture

JS: I am requesting the image-asset...
JS: starting the promise...
JS: my picturePath_1 is  /storage/emulated/0/Android/data/com.igefa.igefago/files/NSIMG_20170922_171753.jpg
JS: starting picture Intent...
JS: finished picture Intent!
JS: starting foreground activity...

-- picture is taken here

JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  6
JS: Rotating the picture by 90 degrees
JS: will resolve asset now...
JS: resolved asset
JS: I've got the image-asset!
JS: application resumed

Second picture (still correct, but look at the double call)

JS: I am requesting the image-asset...
JS: starting the promise...
JS: my picturePath_1 is  /storage/emulated/0/Android/data/com.igefa.igefago/files/NSIMG_20170922_171828.jpg
JS: starting picture Intent...
JS: finished picture Intent!
JS: starting foreground activity...

-- picture is taken here

JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  6
JS: Rotating the picture by 90 degrees
JS: will resolve asset now...
JS: resolved asset

-- what happens now?

JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  0
JS: will resolve asset now...
JS: resolved asset
JS: I've got the image-asset!
JS: application resumed

Third picture

JS: I am requesting the image-asset...
JS: starting the promise...
JS: my picturePath_1 is  /storage/emulated/0/Android/data/com.igefa.igefago/files/NSIMG_20170922_17202.jpg
JS: starting picture Intent...
JS: finished picture Intent!
JS: starting foreground activity...

-- picture is taken here

JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  6
JS: Rotating the picture by 90 degrees
JS: will resolve asset now...
JS: resolved asset

-- ???

JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  0
JS: will resolve asset now...
JS: resolved asset
JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  0
JS: will resolve asset now...
JS: resolved asset
JS: I've got the image-asset!
JS: application resumed

Fourth picture

JS: I am requesting the image-asset...
JS: starting the promise...
JS: my picturePath_1 is  /storage/emulated/0/Android/data/com.igefa.igefago/files/NSIMG_20170922_172030.jpg
JS: starting picture Intent...
JS: finished picture Intent!
JS: starting foreground activity...

-- picture is taken here

JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  6
JS: Rotating the picture by 90 degrees
JS: will resolve asset now...
JS: resolved asset
JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  0
JS: will resolve asset now...
JS: resolved asset
JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  0
JS: will resolve asset now...
JS: resolved asset
JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  0
JS: will resolve asset now...
JS: resolved asset
JS: I've got the image-asset!
JS: application resumed

This behaviour stacks until the app dies with an OutOfMemory Error – the full stacktrace is shown below.

JS: ERROR Error: Uncaught (in promise): Error: java.lang.OutOfMemoryError: Failed to allocate a 600636 byte allocation with 148804 free bytes and 145KB until OOM
JS:     dalvik.system.VMRuntime.newNonMovableArray(Native Method)
JS:     android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
JS:     android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
JS:     android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:728)
JS:     android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:477)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:912)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:896)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:888)
JS:     com.tns.NativeScriptActivity.onActivityResult(NativeScriptActivity.java:69)
JS:     android.app.Activity.dispatchActivityResult(Activity.java:6549)
JS:     android.app.ActivityThread.deliverResults(ActivityThread.java:4063)
JS:     android.app.ActivityThread.handleSendResult(ActivityThread.java:4110)
JS:     android.app.ActivityThread.access$1400(ActivityThread.java:177)
JS:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1498)
JS:     android.os.Handler.dispatchMessage(Handler.java:102)
JS:     android.os.Looper.loop(Looper.java:145)
JS:     android.app.ActivityThread.main(ActivityThread.java:5951)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     java.lang.reflect.Method.invoke(Method.java:372)
JS:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
JS:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
JS: Error: java.lang.OutOfMemoryError: Failed to allocate a 600636 byte allocation with 148804 free bytes and 145KB until OOM
JS:     dalvik.system.VMRuntime.newNonMovableArray(Native Method)
JS:     android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
JS:     android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
JS:     android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:728)
JS:     android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:477)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:912)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:896)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:888)
JS:     com.tns.NativeScriptActivity.onActivityResult(NativeScriptActivity.java:69)
JS:     android.app.Activity.dispatchActivityResult(Activity.java:6549)
JS:     android.app.ActivityThread.deliverResults(ActivityThread.java:4063)
JS:     android.app.ActivityThread.handleSendResult(ActivityThread.java:4110)
JS:     android.app.ActivityThread.access$1400(ActivityThread.java:177)
JS:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1498)
JS:     android.os.Handler.dispatchMessage(Handler.java:102)
JS:     android.os.Looper.loop(Looper.java:145)
JS:     android.app.ActivityThread.main(ActivityThread.java:5951)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     java.lang.reflect.Method.invoke(Method.java:372)
JS:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
JS:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
JS:     at ImageAsset.getImageAsync (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-asset/image-asset.js:25:53)
JS:     at file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-source/image-source.js:32:19
JS:     at new ZoneAwarePromise (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:776:29)
JS:     at ImageSource.fromAsset (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-source/image-source.js:31:16)
JS:     at file:///data/data/com.igefa.igefago/files/app/pages/notedetails/notedetails.component.js:177:46
JS: 
JS:     at ZoneDelegate.invoke (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:365:26)
JS:     at Object.onInvoke (file:///data/data/com.igefa.igefago/files/app/tns_modules/@angular/core/bundles/core.umd.js:4132:37)
JS:     at ZoneDelegate.invoke (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:364:32)
JS:     at Zone.run (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:125:43)
JS:     at file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:760:57
JS:     at ZoneDelegate.invokeTask (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:398:31)
JS:     at Object.onInvokeTask (file:///data/data/com.igefa.igefago/files/app/tns_modules/@angular/core/bundles/core.umd.js:4123:37)
JS:     at ZoneDelegate.invokeTask (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:397:36)
JS:     at Zone.runTask (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:165:47)
JS:     at drainMicroTaskQueue (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:593:35)
JS: Unhandled Promise rejection: java.lang.OutOfMemoryError: Failed to allocate a 600636 byte allocation with 107296 free bytes and 104KB until OOM
JS:     dalvik.system.VMRuntime.newNonMovableArray(Native Method)
JS:     android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
JS:     android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
JS:     android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:728)
JS:     android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:477)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:912)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:896)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:888)
JS:     com.tns.NativeScriptActivity.onStart(NativeScriptActivity.java:38)
JS:     android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1234)
JS:     android.app.Activity.performStart(Activity.java:6329)
JS:     android.app.Activity.performRestart(Activity.java:6399)
JS:     android.app.Activity.performResume(Activity.java:6404)
JS:     android.app.ActivityThread.performResumeActivity(ActivityThread.java:3392)
JS:     android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3434)
JS:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
JS:     android.os.Handler.dispatchMessage(Handler.java:102)
JS:     android.os.Looper.loop(Looper.java:145)
JS:     android.app.ActivityThread.main(ActivityThread.java:5951)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     java.lang.reflect.Method.invoke(Method.java:372)
JS:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
JS:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183) ; Zone: <root> ; Task: Promise.then ; Value: Error: java.lang.OutOfMemoryError: Failed to allocate a 600636 byte allocation with 107296 free bytes and 104KB until OOM
JS:     dalvik.system.VMRuntime.newNonMovableArray(Native Method)
JS:     android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
JS:     android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
JS:     android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:728)
JS:     android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:477)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:912)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:896)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:888)
JS:     com.tns.NativeScriptActivity.onStart(NativeScriptActivity.java:38)
JS:     android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1234)
JS:     android.app.Activity.performStart(Activity.java:6329)
JS:     android.app.Activity.performRestart(Activity.java:6399)
JS:     android.app.Activity.performResume(Activity.java:6404)
JS:     android.app.ActivityThread.performResumeActivity(ActivityThread.java:3392)
JS:     android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3434)
JS:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
JS:     android.os.Handler.dispatchMessage(Handler.java:102)
JS:     android.os.Looper.loop(Looper.java:145)
JS:     android.app.ActivityThread.main(ActivityThread.java:5951)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     java.lang.reflect.Method.invoke(Method.java:372)
JS:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
JS:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183) Error: java.lang.OutOfMemoryError: Failed to allocate a 600636 byte allocation with 107296 free bytes and 104KB until OOM
JS:     dalvik.system.VMRuntime.newNonMovableArray(Native Method)
JS:     android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
JS:     android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
JS:     android.graphics.BitmapFactory.decodeStr
JS: eam(BitmapFactory.java:728)
JS:     android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:477)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:912)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:896)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:888)
JS:     com.tns.NativeScriptActivity.onStart(NativeScriptActivity.java:38)
JS:     android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1234)
JS:     android.app.Activity.performStart(Activity.java:6329)
JS:     android.app.Activity.performRestart(Activity.java:6399)
JS:     android.app.Activity.performResume(Activity.java:6404)
JS:     android.app.ActivityThread.performResumeActivity(ActivityThread.java:3392)
JS:     android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3434)
JS:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
JS:     android.os.Handler.dispatchMessage(Handler.java:102)
JS:     android.os.Looper.loop(Looper.java:145)
JS:     android.app.ActivityThread.main(ActivityThread.java:5951)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     java.lang.reflect.Method.invoke(Method.java:372)
JS:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
JS:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
JS:     at ImageAsset.getImageAsync (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-asset/image-asset.js:25:53)
JS:     at file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-source/image-source.js:32:19
JS:     at new ZoneAwarePromise (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:776:29)
JS:     at ImageSource.fromAsset (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-source/image-source.js:31:16)
JS:     at Object.fromAsset (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-source/image-source.js:189:18)
JS:     at ImageBase._createImageSourceFromSrc (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/image/image-common.js:101:28)
JS:     at Image._createImageSourceFromSrc (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/image/image.js:98:56)
JS:     at Image.(anonymous function) (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/image/image.js:151:14)
JS:     at applyPendingNativeSetters (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/properties/properties.js:900:28)
JS:     at Object.initNativeView (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/properties/properties.js:862:9)
JS:     at Image.ViewBase.onResumeNativeUpdates (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:670:22)
JS:     at Image.ViewBase._resumeNativeUpdates (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:228:18)
JS:     at Image.ViewBase.onLoaded (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:206:14)
JS:     at Image.View.onLoaded (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view/view.js:62:35)
JS:     at file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:212:19
JS: Error: Uncaught (in promise): Error: java.lang.OutOfMemoryError: Failed to allocate a 600636 byte allocation with 107296 free bytes and 104KB until OOM
JS:     dalvik.system.VMRuntime.newNonMovableArray(Native Method)
JS:     android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
JS:     android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
JS:     android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:728)
JS:     android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:477)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:912)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:896)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:888)
JS:     com.tns.NativeScriptActivity.onStart(NativeScriptActivity.java:38)
JS:     android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1234)
JS:     android.app.Activity.performStart(Activity.java:6329)
JS:     android.app.Activity.performRestart(Activity.java:6399)
JS:     android.app.Activity.performResume(Activity.java:6404)
JS:     android.app.ActivityThread.performResumeActivity(ActivityThread.java:3392)
JS:     android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3434)
JS:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
JS:     android.os.Handler.dispatchMessage(Handler.java:102)
JS:     android.os.Looper.loop(Looper.java:145)
JS:     android.app.ActivityThread.main(ActivityThread.java:5951)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     java.lang.reflect.Method.invoke(Method.java:372)
JS:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
JS:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
JS: Error: java.lang.OutOfMemoryError: Failed to allocate a 600636 byte allocation with 107296 free bytes and 104KB until OOM
JS:     dalvik.system.VMRuntime.newNonMovableArray(Native Method)
JS:     android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
JS:     android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
JS:     android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:728)
JS:     android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:477)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:912)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:896)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:888)
JS:     com.tns.NativeScriptActivity.onStart(NativeScriptActivity.java:38)
JS:     android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1234)
JS:     android.app.Activity.performStart(Activity.java:6329)
JS:     android.app.Activity.performRestart(Activity.java:6399)
JS:     android.app.Activity.performResume(Activity.java:6404)
JS:     android.app.ActivityThread.performResumeActivity(ActivityThread.java:3392)
JS:     android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3434)
JS:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
JS:     android.os.Handler.dispatchMessage(Handler.java:102)
JS:     android.os.Looper.loop(Looper.java:145)
JS:     android.app.ActivityThread.main(ActivityThread.java:5951)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     java.lang.reflect.Method.invoke(Method.java:372)
JS:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
JS:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
JS:     at ImageAsset.getImageAsync (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-asset/image-asset.js:25:53)
JS:     at file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-source/image-source.js:32:19
JS:     at new ZoneAwarePromise (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:776:29)
JS:     a
JS: t ImageSource.fromAsset (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-source/image-source.js:31:16)
JS:     at Object.fromAsset (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-source/image-source.js:189:18)
JS:     at ImageBase._createImageSourceFromSrc (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/image/image-common.js:101:28)
JS:     at Image._createImageSourceFromSrc (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/image/image.js:98:56)
JS:     at Image.(anonymous function) (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/image/image.js:151:14)
JS:     at applyPendingNativeSetters (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/properties/properties.js:900:28)
JS:     at Object.initNativeView (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/properties/properties.js:862:9)
JS:     at Image.ViewBase.onResumeNativeUpdates (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:670:22)
JS:     at Image.ViewBase._resumeNativeUpdates (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:228:18)
JS:     at Image.ViewBase.onLoaded (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:206:14)
JS:     at Image.View.onLoaded (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view/view.js:62:35)
JS:     at file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:212:19

modified nativescripe-camera.android.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var applicationModule = require("application");
var imageAssetModule = require("image-asset");
var trace = require("trace");
var platform = require("platform");
var REQUEST_IMAGE_CAPTURE = 3453;
var REQUEST_REQUIRED_PERMISSIONS = 1234;
exports.takePicture = function (options) {
    return new Promise(function (resolve, reject) {
        try {
            console.log("starting the promise...");
            if (android.support.v4.content.ContextCompat.checkSelfPermission(applicationModule.android.currentContext, android.Manifest.permission.CAMERA) != android.content.pm.PackageManager.PERMISSION_GRANTED) {
                reject(new Error("Application does not have permissions to use Camera"));
                return;
            }
            var types = require("utils/types");
            var utils = require("utils/utils");
            var saveToGallery_1;
            var reqWidth_1;
            var reqHeight_1;
            var shouldKeepAspectRatio_1;
            var density = utils.layout.getDisplayDensity();
            if (options) {
                saveToGallery_1 = options.saveToGallery ? true : false;
                reqWidth_1 = options.width ? options.width * density : 0;
                reqHeight_1 = options.height ? options.height * density : reqWidth_1;
                shouldKeepAspectRatio_1 = types.isNullOrUndefined(options.keepAspectRatio) ? true : options.keepAspectRatio;
            }
            if (android.support.v4.content.ContextCompat.checkSelfPermission(applicationModule.android.currentContext, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != android.content.pm.PackageManager.PERMISSION_GRANTED) {
                saveToGallery_1 = false;
            }
            var takePictureIntent = new android.content.Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            var dateStamp = createDateTimeStamp();
            var picturePath_1;
            var nativeFile = void 0;
            var tempPictureUri = void 0;
            if (saveToGallery_1) {
                picturePath_1 = android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DCIM).getAbsolutePath() + "/Camera/" + "NSIMG_" + dateStamp + ".jpg";
                nativeFile = new java.io.File(picturePath_1);
            }
            else {
                picturePath_1 = utils.ad.getApplicationContext().getExternalFilesDir(null).getAbsolutePath() + "/" + "NSIMG_" + dateStamp + ".jpg";
                console.log("my picturePath_1 is ", picturePath_1);
                nativeFile = new java.io.File(picturePath_1);
            }
            var sdkVersionInt = parseInt(platform.device.sdkVersion);
            if (sdkVersionInt >= 21) {
                tempPictureUri = android.support.v4.content.FileProvider.getUriForFile(applicationModule.android.currentContext, applicationModule.android.nativeApp.getPackageName() + ".provider", nativeFile);
            }
            else {
                tempPictureUri = android.net.Uri.fromFile(nativeFile);
            }
            takePictureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, tempPictureUri);
            if (options && options.cameraFacing === "front") {
                takePictureIntent.putExtra("android.intent.extras.CAMERA_FACING", android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
            }
            console.log("starting picture Intent...");
            if (takePictureIntent.resolveActivity(utils.ad.getApplicationContext().getPackageManager()) != null) {
                console.log("finished picture Intent!");
                var appModule_1 = require("application");
                appModule_1.android.on("activityResult", function (args) {
                    console.log("got activity result!");
                    var requestCode = args.requestCode;
                    var resultCode = args.resultCode;
                    if (requestCode === REQUEST_IMAGE_CAPTURE && resultCode === android.app.Activity.RESULT_OK) {
                        console.log("got requestCode ", requestCode , " and resultCode ", resultCode);
                        if (saveToGallery_1) {
                            try {
                                var callback = new android.media.MediaScannerConnection.OnScanCompletedListener({
                                    onScanCompleted: function (path, uri) {
                                        if (trace.isEnabled()) {
                                            trace.write("image from path " + path + " has been successfully scanned!", trace.categories.Debug);
                                        }
                                    }
                                });
                                android.media.MediaScannerConnection.scanFile(appModule_1.android.context, [picturePath_1], null, callback);
                            }
                            catch (ex) {
                                if (trace.isEnabled()) {
                                    trace.write("An error occurred while scanning file " + picturePath_1 + ": " + ex.message + "!", trace.categories.Debug);
                                }
                            }
                        }
                        var exif = new android.media.ExifInterface(picturePath_1);
                        var orientation_1 = exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, android.media.ExifInterface.ORIENTATION_NORMAL);
                        console.log("my orientation is ", orientation_1);
                        if (orientation_1 === android.media.ExifInterface.ORIENTATION_ROTATE_90) {
                            console.log("Rotating the picture by 90 degrees");
                            rotateBitmap(picturePath_1, 90);
                        }
                        else if (orientation_1 === android.media.ExifInterface.ORIENTATION_ROTATE_180) {
                            console.log("Rotating the picture by 180 degrees");
                            rotateBitmap(picturePath_1, 180);
                        }
                        else if (orientation_1 === android.media.ExifInterface.ORIENTATION_ROTATE_270) {
                            console.log("Rotating the picture by 270 degrees");
                            rotateBitmap(picturePath_1, 270);
                        }
                        var asset = new imageAssetModule.ImageAsset(picturePath_1);
                        asset.options = {
                            width: reqWidth_1,
                            height: reqHeight_1,
                            keepAspectRatio: shouldKeepAspectRatio_1
                        };
                        console.log("will resolve asset now...");
                        resolve(asset);
                        console.log("resolved asset");
                    }
                });
                console.log("starting foreground activity...");
                appModule_1.android.foregroundActivity.startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
            }
        }
        catch (e) {
            if (reject) {
                reject(e);
            }
        }
    });
};

The snippet calling the camera plugin

    private takePictureWithCamera() {
        const _that = this;
        let options = {width: 300, height: 300, keepAspectRatio: true, saveToGallery: false};
        console.log("I am requesting the image-asset...")
        camera.takePicture(options).then((imageAsset) => {
            console.log("I've got the image-asset!")
            let image = <Image>_that.noteImage.nativeElement;
            image.src = imageAsset;
            _that.note.hasImage = true;
            new ImageSource().fromAsset(imageAsset).then(imageSource => {
                _that.note.image = imageSource.toBase64String("png");
            });
        }).catch((err) => {
            console.log("Error -> " + err.message);
            if (isIOS) {
                // No error is given back for iOS
            } else {
                if (err.message === "Application does not have permissions to use Camera") {
                    dialogs.alert({
                        title: 'Kein Zugriff auf die Kamera möglich',
                        message: 'Bitte gestatten Sie der App den Zugriff auf die Kamera',
                        okButtonText: 'OK'
                    }).then(result => {
                        camera.requestPermissions();
                    });
                    return;
                }
            }
        });
    }

Which platform(s) does your issue occur on?

Android 5.0.1 on Samsung Galaxy S4

Please provide the following version numbers that your issue occurs with

"dependencies": { "@ angular/animations": "4.0.1", "@ angular/common": "4.0.1", "@ angular/compiler": "4.0.1", "@ angular/core": "4.0.1", "@ angular/forms": "4.0.1", "@ angular/http": "4.0.1", "@ angular/platform-browser": "4.0.1", "@ angular/platform-browser-dynamic": "4.0.1", "@ angular/router": "4.0.1", "@ angular/upgrade": "4.0.1", "base-64": "^0.1.0", "moment": "^2.18.1", "nativescript-10hook-release-info": "^1.0.0", "nativescript-angular": "~3.1.0", "nativescript-badge-button": "^0.1.1", "nativescript-camera": "^3.1.2", "nativescript-cardview": "^2.0.2", "nativescript-couchbase": "^1.0.18", "nativescript-drop-down": "^3.1.0", "nativescript-floatingactionbutton": "^3.0.1", "nativescript-hockey-sdk": "^1.2.0", "nativescript-hook": "^0.2.1", "nativescript-i18n": "^0.2.2", "nativescript-ibeacon": "0.8.1", "nativescript-imagepicker": "^3.0.4", "nativescript-iqkeyboardmanager": "^1.1.0", "nativescript-loading-indicator": "^2.3.2", "nativescript-local-notifications": "^1.2.1", "nativescript-ngx-fonticon": "^2.2.0", "nativescript-pulltorefresh": "^2.0.2", "nativescript-push-notifications": "^0.1.3", "nativescript-ripple": "^2.0.0", "nativescript-sidedrawer": "^1.0.6", "nativescript-snackbar": "^1.1.7", "nativescript-statusbar": "^3.0.1", "nativescript-telerik-ui": "3.0.4", "nativescript-theme-core": "~1.0.2", "nativescript-unit-test-runner": "^0.3.4", "nativescript-web-image-cache": "^4.1.0", "reflect-metadata": "~0.1.8", "rxjs": "~5.3.0", "tns-core-modules": "^3.1.0", "utf8": "^2.1.2", "zone.js": "~0.8.5" }

"tns-android": { "version": "3.1.1" }

node version v6.11.1

I'd be happy to hear from you on this one, guys!

tsonevn commented 7 years ago

Hi @timogroeger, Thank you for the given description for the problem. Regarding that could you provide some more info about the project and how you attached the Image source for the ImageView component. It would be really helpful if you could send us sample project, which demonstrates the issue and could be debugged locally on our side.

In the meantime, I would suggest to review the sample project here and to verify, whether you will have the same problem while building it on your device. Something more, you could also try to attach directly the imageAsset for the ImageView source instead of on converting it to a base64 string and to validate if the rotation and the OutOfMemory problem still exists. Similar to the example.

Also, keep in mind that toBase64String method does not work properly at this time. This is already logged here. Workaround about this could be found here.

tsonevn commented 7 years ago

closing due to inactivity