【发布时间】:2016-02-08 16:57:50
【问题描述】:
我正在开发 VS2015 cordova 应用程序。当我从图库中获取图像并将其转换为 base64string 时出现问题。我成功获得了base64string,但是当我显示它时,我总是得到黑色图像。这是我的代码:
function onPhotoURISuccess(imageURI) {
var largeImage = document.getElementById('smallImage');
largeImage.style.display = 'block';
largeImage.src = imageURI;
basestrg = encodeImageUri(imageURI);
}
function getPhoto(source) {
navigator.camera.getPicture(onPhotoURISuccess, onFail, {
destinationType: Camera.DestinationType.NATIVE_URI, mediaType: Camera.MediaType.Photo,
sourceType: source
});
}
function encodeImageUri(imageUri) {
var c = document.createElement('canvas');
var ctx = c.getContext("2d");
var img = new Image();
img.onload = function () {
c.width = this.width;
c.height = this.height;
ctx.drawImage(img, 0, 0);
};
img.src = imageUri;
var dataURL = c.toDataURL("image/jpeg");
return dataURL;
}
任何想法
【问题讨论】:
标签: jquery cordova phonegap-plugins visual-studio-cordova