navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 70, destinationType: destinationType.DATA_URL,targetWidth: 250,targetHeight: 250,correctOrientation:true });
function onPhotoDataSuccess(imageData) { saveImageToDB(imageData,1); 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,0,0); var dataURL = canvas.toDataURL(outputFormat || 'image/png'); callback.call(this, dataURL); canvas = null; }; img.src = url; } //这里的imagePath用你的图片路径来替换; convertImgToBase64(imagePath, function(base64Img){ alert(base64Img.length); });