$ cordovaCamera为透明PNG添加了黑色背景

时间:2016-08-02 04:26:45

标签: cordova camera base64 transparency cordova-plugins

插件:https://github.com/apache/cordova-plugin-camera

var options = {
  quality: 100,
  destinationType: Camera.DestinationType.DATA_URL,
  sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
  allowEdit: true,
  encodingType: Camera.EncodingType.PNG,
  targetWidth: 128,
  targetHeight: 128,
  popoverOptions: CameraPopoverOptions,
  saveToPhotoAlbum: false
};

我能够成功获得ImageURI,但问题是当我选择透明背景的PNG文件时,它会变黑。如果它有帮助,我将imageURI转换为blob。

imageUri = "data:image/png;base64," + imageData;

  dataURItoBlob = function(dataURI) {
    var binary = atob(dataURI.split(',')[1]);
    var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
    var array = [];
    for (var i = 0; i < binary.length; i++) {
      array.push(binary.charCodeAt(i));
    }
    return new Blob([new Uint8Array(array)], {
      type: mimeString
    });
  };

0 个答案:

没有答案