How to convert iamge to data uri ionic

别等时光非礼了梦想. 提交于 2019-12-25 16:44:10

问题


I am using one camera app. In that after i took photot i need to convert that image to data uri and then have to send to db.

here is what i did :

function opencamer() {

   console.log("camer open");
   Camera.getPicture().then(function(imageURI) {
      console.log(imageURI);
      $scope.lastPhoto = imageURI;
      $scope.imgUrl = "data:image/jpeg;base64," + imageURI;
    }, function(err) {
      console.err(err);
    }, {
      quality: 75,
      targetWidth: 320,
      targetHeight: 320,
      saveToPhotoAlbum: false
    });


}

but when i sent this $scope.imgUrl to db. i was not able to get data uri.please help me out how can i solve this.

i am truck more than 3 hr. not able to find solution.please help me out.

thanks


回答1:


Here is the working code

    $scope.opencamer= function () {
              var options = {
                quality: 75,
                destinationType: Camera.DestinationType.DATA_URL,
                sourceType: Camera.PictureSourceType.CAMERA,
                allowEdit: true,
                encodingType: Camera.EncodingType.JPEG,
                targetWidth: 300,
                targetHeight: 300,
                popoverOptions: CameraPopoverOptions,
                saveToPhotoAlbum: false
            };

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


                }, function (err) {
                    // An error occured. Show a message to the user
                });
            }

send $scope.lastPhoto to your db instead of $scope.imgUrl



来源:https://stackoverflow.com/questions/43014164/how-to-convert-iamge-to-data-uri-ionic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!