cordova-plugin-camera-preview
cordova-plugin-camera-preview copied to clipboard
Take Picture function is too slow
I have a issue in iOS platform.
The Take Picture function have a very delay to return the picture captured. This occurs in iOS 9.3 and iOS 10.
I tried using 0.0.8 and 0.0.9 (westonganger), but no success.
Are you trying with native/default resolution? I faced some problem but because I was taking the picture with more than 4000px
No. I was set a 810x810 picture. In version 0.0.8, I received 2 results (original and preview images, both in the filesystem). In version 0.0.9 I received a base64 string with full resolution, not respect the parameters set previously.
Wherever, the camera was slow in the both cases.
Try updating new version. Also try with a different device
any update on this matter?
Probably not but it helps in order to be sure others forked repositories have the same issue, so it's not a regression issue
I'm also seeing takePicture() need several seconds (sometimes 10!) to process a 1500px image on iOS iPhone 6. Why the difference compared to the normal camera that can capture multiple photos quickly?
any updates on this?
+1
check ou my fork, it saves the image in file system but it is really fast. I made some changes and added a background thread. check it out. https://github.com/HartHerbert/cordova-plugin-camera-preview.git
@HartHerbert just wondering how are you using your plugin? camera options ? how do you preview the picture after taking it. it still feels slow taking the picture. do you wrap anything in ngzone by any chance? i have the nav ctrl push to another page and display the picture but the overall process takes 4 seconds?
this is my take picture method on my page. in the Camera.takepicture method is the version with the filepath and outcommented the version with the base64 (old method from the original plugin) this version is very fast with ios. for android I am still making some changes to make it faster.
`takePicture(){
if(this.enableTakePicture == false){
return;
}
let self = this;
CameraPreview.getSupportedPictureSizes(function(dimensions){
// note that the portrait version, width and height swapped, of these dimensions are also supported
dimensions.forEach(function(dimension) {
if(dimension.width > self.supportedPreviewSize.width && dimension.width < 3000){
if((dimension.width/dimension.height > 1.6 && dimension.width/dimension.height < 1.9)
|| (dimension.height/dimension.width > 1.6 && dimension.height/dimension.width < 1.9))
self.supportedPreviewSize = {width:dimension.width, height:dimension.height};
console.log("NEW SUPPORTED: ", self.supportedPreviewSize);
}
});
});
setTimeout(()=>{
let tthis = this;
if(this.takingPicture == true){
//only a photo at once
return;
}
this.ga.trackEvent('Create','Photo',this.camera_facing);
this.takingPicture = true;
console.log("SIZE:",this.supportedPreviewSize);
CameraPreview.takePicture({width:this.supportedPreviewSize.width, height:this.supportedPreviewSize.height,
quality: 100}, function(filepath){
tthis.takingPicture = false;
tthis.navCtrl.push('EditImagePage',{results:filepath});
console.log("ENTERED CAMERA TAKE PICTURE");
/*tthis.ngZone.runOutsideAngular(()=>{
console.log("entered takePicture");
let imageSrcData = base64PictureData[0];
let blob:Blob = tthis.b64toBlob(imageSrcData, 'image/jpeg', 1024);
let fileName = tthis.globalState.username + "-" + Date.now()+".jpg";
let directory = tthis.file.dataDirectory+"takenPictures/";
let fullImagePath = directory + fileName;
let options = {};
tthis.ngZone.run(()=>{
tthis.file.writeFile(directory,fileName, blob,options).then((res:any)=>{
try{
tthis.takingPicture = false;
tthis.navCtrl.push('EditImagePage',{results:fullImagePath});
}catch(error){
console.error("setonPictaken Error: ", error);
}
},(error)=>{
console.error("Error while saving image", error);
});
})
});*/
});
},50);
}`
@HartHerbert thanks for the code I just tried it, from pressing the icon that run the take picture function to displaying the image in another page takes me 3-4 seconds. I am using iPhone 6. Now during that process the image preview is still displaying live feed are you using sound feedback to let the user they have taken the picture to reduce confusion? is yours faster than 3-4 second?
cheers A
@HartHerbert FYI: using your fork i get; platforms/android/src/com/cordovaplugincamerapreview/CameraActivity.java:41: error: package com.bumptech.glide.load.data does not exist import com.bumptech.glide.load.data.ExifOrientationStream;
i also encounter this on an iphone, on android it goes faster, but not as fast as you expect, but i guess that is the downside of using a plugin like this... :/
@HartHerbert, I tried out your fork on iOS, and it does indeed take the picture much faster than the original. In my case, it went down from about 11 seconds to about 1.5 seconds. But, I found that now that I have to read the file from the filesystem, that process is taking about 10 seconds, so I've had no gain at all. Is reading the file slow for you as well?
Any update on this?
I did some debugging on this, and found that the delay is caused at line 738 of invokeTakePicture():
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.onPictureTakenHandlerId];
I assume this is what sends the base64 image string to my javascript success handler. But why is it so slow? Is it just because the image data is large (it's only about 150k)?
Does anyone know of any ways to improve this?
+1
Hi Everyone,
I've done some further investigation, and I'm no longer convinced this is a real problem. I've been basing my measurements of the delay on the Xcode log. I was logging and entry just before calling takePicture(), and then first thing in the success callback. I always saw a 10 second gap between those two log entries.
But then I started also logging to a database on the device, as I wanted to capture this data for later analysis, while my app was in use. What I found was that the log timestamps that I captured on the device did NOT show this gap, and did not correspond with the Xcode log timestamps. The success callback was in fact called within about 1.5 seconds.
I can only guess that the Xcode log timestamps are somehow delayed. Perhaps they are only added to the log entries when the data arrives in the debugger, and they are perhaps transferred in batch when the device is not busy?