gpt4 book ai didi

javascript - (Javascript) 使用文件路径创建一个 File 对象

转载 作者:行者123 更新时间:2023-12-02 05:02:29 25 4
gpt4 key购买 nike

我正在制作一个基于 cordova 的应用程序。是否可以使用文件路径创建一个 File 对象?

我要做的是拍照并将图片显示在 Canvas 上。在 android 中,它工作正常但在 ios6 中,由于 ios6 上的 mega-fixel 问题,在 Canvas 上绘制时图片损坏。

然后我在下面找到了一个插件

https://github.com/stomita/ios-imagefile-megapixel

插件需要一个 File 或 Blob 参数,但我只有文件 URL。如何从文件 URL 获取文件或 Blob 对象?

我的来源在下面

takePicture : function(onSuccess, onError) {
options = {
quality : 50,
destinationType : navigator.camera.DestinationType.FILE_URI, //device returns File URL
correctOrientation : true
};
navigator.camera.getPicture(onSuccess, onError, options);
}
onSuccess : function (photo_src) {
$('#photo_hidden').attr('src', photo_src);
setTimeout(function() {
copyImage('photo_hidden', 'a04_image');
}, 500);
}
copyImage : function (sourceId, targetId) {
try{
var source = document.getElementById(sourceId);
var source_w = source.width;
var source_h = source.height;
var target = document.getElementById(targetId);
var target_w = target.width;
var target_h = target.height;
target_h = Math.round(target_w / source_w * source_h);
/////////////////////
// I want to make a File object from source.src HERE!!
/////////////////////
//TODO this part will be changed to use plugin
if (target.getContext) {
var context = target.getContext('2d');
context.drawImage(source, 0, 0, source_w, source_h, 0, 0, target_w, target_h);
}
//
}catch (e) {
console.log(e);
}
}

如果不可能,欢迎任何制作 File 或 Blob 对象的想法

提前致谢

最佳答案

我自己解决了这个问题。

没有用户的操作就无法创建文件对象。(需要使用<input type='file'>标签)

我查看了插件源。

我发现参数不一定是文件对象。

可以使用图像对象。

关于javascript - (Javascript) 使用文件路径创建一个 File 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15037729/

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