CordovaCamera总是一张Square照片吗?

时间:2016-01-27 17:13:38

标签: cordova ionic-framework cordova-plugins

我需要更改什么才能让CordovaCamera不再制作Square照片?

现在我打电话给这段代码:

 var options = {
          quality: 100,
          destinationType: Camera.DestinationType.DATA_URL,
          sourceType: Camera.PictureSourceType.CAMERA,
          allowEdit: true,
          encodingType: Camera.EncodingType.JPEG,
          // targetWidth: 1600,
          // targetHeight: 1280,
          popoverOptions: CameraPopoverOptions,
          saveToPhotoAlbum: false,
          correctOrientation:true
        };

          $cordovaCamera.getPicture(options).then(function (imageData) {
              $scope.imgURI = "data:image/jpeg;base64," + imageData;

它打开相机,你拍照,然后你得到一个你看到广场的屏幕。当你说“使用照片”时,它会保存广场内的图片部分..

3 个答案:

答案 0 :(得分:6)

如果你使用allowEdit: true,,拍照后会进入裁剪画面,裁剪画面总是会出现正方形。

如果您不想要正方形,请使用allowEdit: false,,然后您将使用原始尺寸的原始图像。

答案 1 :(得分:0)

修改 经过一番研究后,我可以看到这仍然要求你裁剪图像。在我的应用程序中,我一直想要使图像正方形,所以它对我来说还不是一个问题。

也许您可以在Ionic论坛上查看此帖子,该论坛似乎就如何解决问题提出了一些建议。

https://forum.ionicframework.com/t/cordova-camera-crop/14661/7

<强> ORIGINAL: 您已注释掉targetWidth和targetHeight变量。如果取消注释这些行,然后将每个行设置为高度和宽度(以像素为单位)。

例如,下面的代码会尝试获得1080p图像的目标宽度(1920px×1080px)

var options = {
      quality: 100,
      destinationType: Camera.DestinationType.DATA_URL,
      sourceType: Camera.PictureSourceType.CAMERA,
      allowEdit: true,
      encodingType: Camera.EncodingType.JPEG,
      targetWidth: 1920,
      targetHeight: 1080,
      popoverOptions: CameraPopoverOptions,
      saveToPhotoAlbum: false,
      correctOrientation:true
};

答案 2 :(得分:0)

您必须在位于此处的.java文件中更改以下代码

平台\ android \ src \ org \ apache \ cordova \ camera \ CameraLauncher.java 第436行

  cropIntent.putExtra("crop", "true");
  cropIntent.putExtra("aspectX", 1);
  cropIntent.putExtra("aspectY", 1);
  cropIntent.putExtra("outputX", 700);
  cropIntent.putExtra("outputY", 700);
  cropIntent.putExtra("return-data", true);