cordova-plugin-camera-preview icon indicating copy to clipboard operation
cordova-plugin-camera-preview copied to clipboard

Take Picture function is too slow

Open renatobezerra opened this issue 8 years ago • 19 comments

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.

renatobezerra avatar Jan 25 '17 14:01 renatobezerra

Are you trying with native/default resolution? I faced some problem but because I was taking the picture with more than 4000px

erperejildo avatar Jan 25 '17 16:01 erperejildo

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.

renatobezerra avatar Jan 26 '17 11:01 renatobezerra

Try updating new version. Also try with a different device

erperejildo avatar Feb 05 '17 22:02 erperejildo

any update on this matter?

harithFED avatar Feb 06 '17 07:02 harithFED

Probably not but it helps in order to be sure others forked repositories have the same issue, so it's not a regression issue

erperejildo avatar Feb 09 '17 16:02 erperejildo

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?

mikewagz avatar May 05 '17 13:05 mikewagz

any updates on this?

hartherbert avatar Jun 30 '17 21:06 hartherbert

+1

andrewvmail avatar Jul 15 '17 10:07 andrewvmail

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 avatar Jul 15 '17 19:07 hartherbert

@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?

andrewvmail avatar Jul 16 '17 07:07 andrewvmail

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 avatar Jul 16 '17 13:07 hartherbert

@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

andrewvmail avatar Jul 17 '17 01:07 andrewvmail

@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;

timomeara avatar Aug 07 '17 04:08 timomeara

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... :/

Lenndev avatar Nov 29 '17 22:11 Lenndev

@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?

p3v9d5ui avatar Feb 25 '18 13:02 p3v9d5ui

Any update on this?

p3v9d5ui avatar Mar 02 '18 12:03 p3v9d5ui

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?

p3v9d5ui avatar Mar 03 '18 17:03 p3v9d5ui

+1

jgutierro avatar Mar 14 '18 11:03 jgutierro

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?

p3v9d5ui avatar Mar 21 '18 11:03 p3v9d5ui