3
我正在製作基於cordova的應用程序。 是否有可能通過文件路徑創建一個File對象?(Javascript)使用文件路徑製作File對象
我要做的就是拍照並在畫布上顯示圖片。 在Android中,它工作正常,但在ios6中,由於ios6上的超級固定點問題而在畫布上繪製時圖片已損壞。
後來我發現下面
https://github.com/stomita/ios-imagefile-megapixel
插件插件需要一個文件或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);
}
}
如果是不可能的,任何想法做一個文件或Blob對象是歡迎
在此先感謝