1
votes

Currently i try to get picture from custom view with Camera Preview, but the result is picture always original size. here my code..

RunCamera() {

let quarter = window.screen.height / 4, mid = quarter + (quarter/2)
const cameraPreviewOpts: CameraPreviewOptions = {
  x: 0,
  y: this.mid,
  width: window.screen.width,
  height: 70,
  camera: 'rear',
  tapPhoto: true,
  previewDrag: true,
  toBack: true,
  alpha: 1
}

// start camera
this.cameraPreview.startCamera(cameraPreviewOpts).then(
  (res) => {
    console.log("startCamera ok",res)
  },
  (err) => {
    console.log("startCamera Err",err)
  });}

Camera will run like bellow.. this run well.. camera running

after this, i need to take picture, but the result is like this..

Image Result

Here my code..

takePic(){

// picture options
const pictureOpts: CameraPreviewPictureOptions = {
  width: 1280,
  height: 1280,
  quality: 85
}

// take a picture
this.cameraPreview.takePicture(pictureOpts).then((imageData) => {
  console.log("takePicture",imageData);
  this.selectedImage = 'data:image/png;base64,' + imageData;

  this.cameraPreview.stopCamera();
}, (err) => {
  console.log(err);
  alert("Error occured while taking picture:"+JSON.stringify(err))
});}

There is anyway to get my goal ?

1

1 Answers

0
votes

Finnaly after 5 days, i cannot freely choose the dimensions when taking a picture. Each device has a fixed set of possible dimensions that can be used. Only these are possible. If i try to take a picture with the options above, the plugin chooses a supportedSize that's closest to the given options.

What i want to have is just a part of the image. So you will need to manipulate the image afterwards. Manipulating images should not be part of this plugin.

https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview/issues/440