nstudio / nativescript-camera-plus

MIT License
79 stars 50 forks source link

(Android) saveToGallery: false issue #2

Closed ShawnPavel closed 5 years ago

ShawnPavel commented 6 years ago

I'm testing in an angular project (see npm versions below). And when executing the takePicture method with saveToGallery set to false like so: this.cameraPlus.takePicture({ saveToGallery: false, confirm: true }); a few things happen that are a bit wonky.

First, the confirm dialog isn't shown. Second, the resultant photoCapturedEvent is invalid.

Here's the debug log: (Note: the console dump is of the e.data in the photo capture event)

JS: CameraPlus video enabled:,false
JS: CameraPlus default camera:,rear
JS: cam loaded
JS: CameraPlus no camera
JS: CameraPlus *** onSurfaceTextureAvailable ***
JS: this.cameraId = 0
JS: CameraPlus *** _initCamera ***
JS: this.cameraId = 0
JS: CameraPlus opening camera with id = 0
JS: cam loaded
JS: CameraPlus supported focus modes = [fixed]
JS: CameraPlus *** _setCameraDisplayOrientation ***
JS: CameraPlus DISPLAY ROTATION = 0
JS: CameraPlus --- setting rotation for back facing camera --- 
JS:  --- info.orientation = 90
JS: CameraPlus result = 90
JS: CameraPlus targetRatio = 1.4222222222222223
JS: CameraPlus targetHeight = 1536
JS: CameraPlus size.width = 640, size.height = 480
JS: CameraPlus ratio = 1.3333333333333333
JS: CameraPlus size.width = 352, size.height = 288
JS: CameraPlus ratio = 1.2222222222222223
JS: CameraPlus size.width = 320, size.height = 240
JS: CameraPlus ratio = 1.3333333333333333
JS: CameraPlus size.width = 176, size.height = 144
JS: CameraPlus ratio = 1.2222222222222223
JS: CameraPlus optimalSize = android.hardware.Camera$Size@13f7860, optimalSize.width = 640, optimalSize.height = 480
JS: CameraPlus mPreviewSize = android.hardware.Camera$Size@13f7860
JS: CameraPlus _initDefaultButtons error,Error: Cannot convert object to Landroid/view/View$OnClickListener; at index 0
JS: CameraPlus {"saveToGallery":false,"confirm":true}
JS: CameraPlus *** _initCamera ***
JS: this.cameraId = 0
JS: CameraPlus opening camera with id = 0
JS: cam loaded
JS: CameraPlus supported focus modes = [fixed]
JS: CameraPlus *** _setCameraDisplayOrientation ***
JS: CameraPlus DISPLAY ROTATION = 0
JS: CameraPlus --- setting rotation for back facing camera --- 
JS:  --- info.orientation = 90
JS: CameraPlus result = 90
JS: CameraPlus targetRatio = 1.4222222222222223
JS: CameraPlus targetHeight = 1536
JS: CameraPlus size.width = 640, size.height = 480
JS: CameraPlus ratio = 1.3333333333333333
JS: CameraPlus size.width = 352, size.height = 288
JS: CameraPlus ratio = 1.2222222222222223
JS: CameraPlus size.width = 320, size.height = 240
JS: CameraPlus ratio = 1.3333333333333333
JS: CameraPlus size.width = 176, size.height = 144
JS: CameraPlus ratio = 1.2222222222222223
JS: CameraPlus optimalSize = android.hardware.Camera$Size@13f7860, optimalSize.width = 640, optimalSize.height = 480
JS: CameraPlus mPreviewSize = android.hardware.Camera$Size@13f7860
JS: CameraPlus Orientation: ,6
JS: CameraPlus originalBmp,
JS: CameraPlus bitmapOptions.inSampleSize,1
JS: CameraPlus originalBmp,android.graphics.Bitmap@91a42cc
JS: CameraPlus finalBmp,android.graphics.Bitmap@8e8342a
JS: CameraPlus recycling originalBmp...
JS: CameraPlus compressing finalBmp...
JS: CameraPlus recycling finalBmp...
JS: CameraPlus byteArray data,[B@201e191
JS: CameraPlus closing outputStream...
JS: CameraPlus picturePath,/storage/emulated/0/Android/data/org.nativescript.camTest/files/IMG_1516747726610.jpg
JS: CameraPlus nativeFile,/storage/emulated/0/Android/data/org.nativescript.camTest/files/IMG_1516747726610.jpg
JS: === dump(): dumping members ===
JS: {
JS:     "_observers": {},
JS:     "_android": "/storage/emulated/0/Android/data/org.nativescript.camTest/files/IMG_1516747726610.jpg",
JS:     "_options": {
JS:         "width": 0,
JS:         "height": 0,
JS:         "keepAspectRatio": true
JS:     }
JS: }
JS: === dump(): dumping function and properties names ===
JS: constructor()
JS: android: /storage/emulated/0/Android/data/org.nativescript.camTest/files/IMG_1516747726610.jpg
JS: getImageAsync()
JS: nativeImage: undefined
JS: get()
JS: set()
JS: on()
JS: off()
JS: addEventListener()
JS: removeEventListener()
JS: notify()
JS: notifyPropertyChange()
JS: hasListeners()
JS: _createPropertyChangeData()
JS: _emit()
JS: _getEventList()
JS: _indexOfListener()
JS: === dump(): finished ===
├── @angular/animations@5.2.1
├── @angular/common@5.2.1
├── @angular/compiler@5.2.1
├── @angular/core@5.2.1
├── @angular/forms@5.2.1
├── @angular/http@5.2.1
├── @angular/platform-browser@5.2.1
├── @angular/platform-browser-dynamic@5.2.1
├── @angular/router@5.2.1
├── @nstudio/nativescript-camera-plus@1.0.0
├── babel-traverse@6.26.0
├── babel-types@6.26.0
├── babylon@6.18.0
├── lazy@1.0.11
├── moment@2.20.1
├── nativescript-angular@5.2.0
├── nativescript-dev-typescript@0.6.0
├── nativescript-theme-core@1.0.4
├── reflect-metadata@0.1.12
├── rxjs@5.5.6
├── tns-core-modules@3.4.0
├── typescript@2.6.2
└── zone.js@0.8.20
manojdcoder commented 5 years ago

Seems to be a bug when saveToGallery is false. The image asset is created from picturePath into which the image data was never written.

@bradmartin In this case may be saving the file to temp folder and return that path might help?

AntoineBouquet commented 5 years ago

From this line of code : https://github.com/nstudio/nativescript-camera-plus/blob/04e55c81271fd7ba17aff990cd811a796f1014bc/src/camera-plus.android.ts#L1479

Seems the saveToGallery === true is too much in the condition and do not allow to save image data in the file when we use saveToGallery = false option

marc007 commented 5 years ago

https://github.com/nstudio/nativescript-camera-plus/blob/b3494e9196c84bbdb3f73d16e2e39f378ada341f/src/camera-plus.android.ts#L1598

@NathanWalker Actually, I would use the line 1597 (after the block mentioned by @AntoineBouquet) and add: this._saveImageToDisk(nativeFile, data);