从照片库中进行选择时,照片将被裁剪

时间:2019-09-01 09:01:24

标签: ios camera ionic3

在我的离子项目中,我可以选择从照片库中选择一个图像,然后在视图中显示选定的图像,问题是图像变大并且当它出现在视图中时被裁剪掉了一部分选择之后。

我尝试过更改目标高度和宽度,但是对此没有影响

selecPicture(name) {
this.camera.getPicture({
  quality: 90,
  destinationType: this.camera.DestinationType.FILE_URI,
  targetHeight: 500,
  targetWidth: 500,
  allowEdit: false,
  correctOrientation: true,
  encodingType: this.camera.EncodingType.JPEG,
  mediaType: this.camera.MediaType.PICTURE,
  sourceType: this.camera.PictureSourceType.PHOTOLIBRARY
}).then((imageData) => {

  let base64Image = "data:image/jpeg;base64," + imageData;
  this.geolocation.getCurrentPosition().then((resp) => {
    let lat = resp.coords.latitude;
    let lon = resp.coords.longitude;
    this.lat = lat;
    this.lon = lon;
    let d = new Date();
    let draftSavedTime = d.toString().substr(4, 11);
    let canvas = this.canvasRef.nativeElement;
    let context = canvas.getContext('2d');
    let newImg = new Image();
    newImg.src = imageData;
    newImg.onload = () => {
      canvas.setAttribute("width", newImg.height);
      canvas.setAttribute("height", newImg.width);
      context.drawImage(newImg, 0, 0, newImg.width, newImg.height);

      context.font = "bold 13px Arial";
      context.fillStyle = 'red';
      context.fillText(draftSavedTime, 20, 20);
      context.fillText('Lat: ' + lat, canvas.width * 0.1, canvas.height * 0.9);
      context.fillText('Lon: ' + lon, canvas.width * 0.1, canvas.height * 0.8);
      let image = canvas.toDataURL();
      this.attachedImages.push(image);
      this.setValue(name, image);
    };
  }).catch((error) => {
    console.log('Error getting location', error);
    {//**to show location service status to the user and take to settings page on turn services on
      let alertGPSError = this.alertCtrl.create({
        title: 'Error',
        message: 'Please turn on the location service',
        buttons: [
          {
            text: 'Settings',
            handler: () => {
              {
                console.log('openNativeSettingsTest is active');
                (<any>window).cordova.plugins.settings.open("wifi", function () {
                  console.log('opened settings');
                },
                  function () {
                    console.log('failed to open settings');
                  }
                );
              }
            }//End handler
          },
          {
            text: 'Cancel',
            handler: () => {
            }
          }
        ]
      });
      alertGPSError.present();

  });
}, (err) => {
  console.log(err);
});

}

不应该裁剪图像,因为我没有使用相机插件的裁剪功能。

0 个答案:

没有答案