gpt4 book ai didi

ionic-framework - ionic native camera.getPicture(options) 总是返回一个字符串

转载 作者:行者123 更新时间:2023-12-04 07:07:47 24 4
gpt4 key购买 nike

我正在使用 @ionic-native/camera 中的 getPicture 函数来获取图像的文件 URI。我有cordova相机插件,所有的包都更新了。根据documentation默认目标类型选项是 File_URI。但是,即使我将默认目标类型明确指定为 File_URI 的选项,它也会返回一个 base64 字符串。

下面给出了源代码,我错过了什么吗?任何帮助表示赞赏。

import { Camera, CameraOptions } from '@ionic-native/camera';
    openGallery(){
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY
}

this.camera.getPicture(options).then((imageURI) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64 (DATA_URL):

this.image_loc = imageURI;

console.log("The image location is as follows: " + this.image_loc);

}, (err) => {
// Handle error
});
}

控制台输出:

enter image description here

最佳答案

尝试这个

 base64Image:any;

optionsCamera: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.PNG,
cameraDirection: this.camera.Direction.BACK,
targetHeight:400,
targetWidth: 400,
correctOrientation: true,
allowEdit: true

}


this.camera.getPicture(options).then((imageData) => {

this.base64Image = imageData;
this.convertToUrl(imageData);

}, (err) => {
// console.log(err);

});


convertToUrl(newImage){
function toDataURL(ctx, callback) {
var url = ctx.base64Image;

var xhr = new XMLHttpRequest();
xhr.onload = function() {
var reader = new FileReader();
reader.onloadend = function() {
ctx.base64Image = reader.result;
callback(reader.result);
}
reader.readAsDataURL(xhr.response);

};
xhr.open('GET', url);
xhr.responseType = 'blob';
xhr.send();
}

toDataURL(this, function(dataUrl) {
console.log(dataUrl)
})


}

关于ionic-framework - ionic native camera.getPicture(options) 总是返回一个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54012585/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com