Phonegap: save base64 image to gallery

后端 未结 3 1046
甜味超标
甜味超标 2021-01-07 13:04

I just wanna save an image base64 and open it on gallery. I don\'t want to get pictures from gallery or take pictures.




        
3条回答
  •  鱼传尺愫
    2021-01-07 14:04

    CLI: cordova plugin add org.apache.cordova.camera

      document.addEventListener("deviceready",onDeviceReady,false);
    
        var pictureSource;   // picture source
        var destinationType; // sets the format of returned value
        function onDeviceReady() {
            pictureSource=navigator.camera.PictureSourceType;
            destinationType=navigator.camera.DestinationType;
        }
    
        $(document).on('click','#pic_parse',function(){
          navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
            encodingType: Camera.EncodingType.PNG,
            destinationType: destinationType.DATA_URL,
            sourceType: pictureSource.SAVEDPHOTOALBUM });
        });
    
        function onPhotoDataSuccess(imageData) { 
            alert(imageData);//here, imageDate is base64.Now, you can save base64.
        }
    
    function onFail(message) {
      alert('Failed because: ' + message);
    }
    

    Hope, it will helps you!

提交回复
热议问题