ionic imgBase64

时间:2021-07-29 21:05:06
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: ,        destinationType: destinationType.DATA_URL,targetWidth: ,targetHeight: ,correctOrientation:true });
function onPhotoDataSuccess(imageData) {
saveImageToDB(imageData,);
smallImage1.style.display = 'block';
smallImage1.src = "data:image/jpeg;base64," + imageData;
}
var imagePath = "img/OBseverLOGO.png";
function convertImgToBase64(url, callback, outputFormat){
var canvas = document.createElement('CANVAS'),
ctx = canvas.getContext('2d'),
img = new Image;
img.crossOrigin = 'Anonymous';
img.onload = function(){
canvas.height = img.height;
canvas.width = img.width;
ctx.drawImage(img,,);
var dataURL = canvas.toDataURL(outputFormat || 'image/png');
callback.call(this, dataURL);
canvas = null;
};
img.src = url;
} //这里的imagePath用你的图片路径来替换; convertImgToBase64(imagePath, function(base64Img){
alert(base64Img.length);
});