使用PhoneGap的,如何让iPhone从照片库中选择照片进行Base64图像数据 [英] Using PhoneGap, How to get base64 image data of the photo chosen from photo library in iPhone
问题描述
使用PhoneGap的(科尔多瓦),想获得从照片库中选择照片进行Base64图像数据。
当照片从相机拍摄,用code在科尔多瓦下面的代码片段,我可以做..。
navigator.camera.getPicture(的onSuccess,onFail,{质量:50,
destinationType:Camera.DestinationType.DATA_URL
});功能的onSuccess(为imageData){
VAR图像=的document.getElementById('MYIMAGE');
image.src =数据:图像/ JPEG; BASE64,+为imageData;
}功能onFail(消息){
警报('因为失败:'+消息);
}
不过,我应该做的就是照片时会从库中选择的base64图像数据吗?
功能连接codeImageUri(imageUri)
{
变种C =使用document.createElement('画布');
变种CTX = c.getContext(2D);
VAR IMG =新的图像();
img.onload =功能(){
c.width = this.width;
c.height = this.height;
ctx.drawImage(IMG,0,0);
};
img.src = imageUri;
VAR dataURL = c.toDataURL(图像/ JPEG);
返回dataURL;
}
我在PhoneGap的这个无解。因此,所有我需要的是已经从他们的照片库中选择用户图像的Base64格式。所以,我把这种形象在画布上和 toDataUrl()给我的十分格式: - )
Using PhoneGap(Cordova), Am trying to get base64 image data of the photo chosen from the photo library.
I could do that.. when the photo is captured from camera, With the below snippet of code in Cordova.
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
destinationType: Camera.DestinationType.DATA_URL
});
function onSuccess(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
}
function onFail(message) {
alert('Failed because: ' + message);
}
But, what should i do to get the base64 image data when the photo gets chosen from library?
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;
}
I have no solution in PhoneGap for this. So all I need is the base64 format of the image which has been chosen by user from their photo library. So I placed that image on canvas and toDataUrl() gave me the very format :-)
这篇关于使用PhoneGap的,如何让iPhone从照片库中选择照片进行Base64图像数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!