我正在制作一个基于cordova的应用程序。
是否可以使用文件路径创建一个File对象?
我的目标是拍照并在画布上展示图片。 在Android中,这很好用,但在iOS6中,由于iOS6上的mega-fixel问题,在画布上绘制时图片会出现损坏。
然后我找到了下面的插件。
如果不可能,欢迎提供任何制作文件或 Blob 对象的想法。
提前感谢。
我的目标是拍照并在画布上展示图片。 在Android中,这很好用,但在iOS6中,由于iOS6上的mega-fixel问题,在画布上绘制时图片会出现损坏。
然后我找到了下面的插件。
https://github.com/stomita/ios-imagefile-megapixel
这个插件需要一个文件或Blob参数,但我只有文件URL。如何从文件URL获取File或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);
}
}
如果不可能,欢迎提供任何制作文件或 Blob 对象的想法。
提前感谢。