当从图像相册中选择图像时,无法读取文件大小
File size not able to read when images is choosed from image album
在我的phonegap应用程序(android版本4.4.2)我需要从sd卡中选择图像。在这种情况下,我无法读取图像大小和名称。我的代码是。
function getSkiImage(id,source){
navigator.camera.getPicture(function(imageURI){
alert(imageURI);
window.resolveLocalFileSystemURI(imageURI, function(fileEntry) {
alert(fileEntry);
fileEntry.file(function(fileObj) {
alert(fileObj.size);
});
});
// tried this also
/*window.requestFileSystem(imageURI, 0, function(data) {
alert(data.size);
}, fail); */
}, fail, { quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: pictureSource.PHOTOLIBRARY });
}
在我的android设备(v 4.4.2)相册显示像"最近","驱动器","图像","画廊",…当从图库中选择图像时,只有图像大小可以获取..而图库图像大小无法获取..
引用了这个,但是没有得到成功
Cordova/PhoneGap照片文件大小
在phonegap文档中他们说:
仅限Android 4.4: Android 4.4引入了新的存储访问框架,使用户更容易浏览和打开文档跨所有首选文档存储提供程序。科尔多瓦有尚未与这个新的存储访问框架完全集成。因此,getPicture()方法将不能正确返回当用户从"最近"、"驱动器"、"图片"中选择图片时,或"外部存储"文件夹,当destinationType为FILE_URI时。然而,用户将能够正确地选择任何图片,如果他们会先通过"图库"应用程序。潜在的解决方法这个问题记录在这个StackOverflow问题上。请参阅CB-5398来跟踪这个问题。
Android使用intent来启动设备上的摄像头活动捕捉图像,在内存较低的手机上,Cordova活动可能会被杀。在此场景中,图像可能不会出现Cordova活动恢复。
<!DOCTYPE html>
<html>
<head>
<title>Capture Photo</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
var pictureSource; // picture source
var destinationType; // sets the format of returned value
// Wait for PhoneGap to connect with the device
//
document.addEventListener("deviceready",onDeviceReady,false);
// PhoneGap is ready to be used!
//
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
getPhoto(pictureSource.PHOTOLIBRARY);
}
function onPhotoURISuccess(imageURI) {
alert(imageURI);
var largeImage = document.getElementById('largeImage');
largeImage.style.display = 'block';
largeImage.src = imageURI;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, rfail);
window.resolveLocalFileSystemURI(imageURI, onResolveSuccess, fail);
}
function rfail(e){
alert(e);
}
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source });
}
function onFileSystemSuccess(fileSystem) {
console.log(fileSystem.name);
}
function bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return 'n/a';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
};
function onResolveSuccess(fileEntry) {
filenameofajax=fileEntry.name;
var efail = function(evt) {
console.log("File entry error "+error.code);
};
var win=function(file) {
console.log(file);
for (var i in file){
alert(i+""+file[i]);
}
alert(bytesToSize(file.size));
};
fileEntry.file(win, efail);
}
function efail(e) {
alert("esa")
}
function fail(e) {
alert("sa")
}
// Called if something bad happens.
//
function onFail(message) {
alert('Failed because: ' + message);
}
</script>
</head>
<body>
<button onclick="capturePhoto();">Capture Photo</button> <br>
<button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br>
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
<button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br>
<img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
<img style="display:none;" id="largeImage" src="" />
</body>
</html>
检查这个
相关文章:
- 通过传递图像的URL通过javascript读取/处理图像-类似于PHP中的file_get_contents
- 未捕获的类型错误: 无法读取未定义的属性“图像”
- Javascript:检测文件读取器中是否有图像
- 在 javascript 中验证或读取远程图像类型
- 从 JavaScript 中的图像中读取像素数据会返回半透明像素的意外结果
- 如何使用AJAX读取图像文件并渲染到Canvas
- 使用Meteor将图像写入/读取到MongoDB中
- 如何从本地文件夹(磁盘存储)读取或获取图像文件,并使用nodejs服务器将其发送到Angularjs
- 如何读取存储在图像的数据src中的URL,并在另一个img控制器的src中设置该URL onclick
- 最佳实现:将图像文件上传到数据库,并从数据库中读取图像
- 小程序:无法读取图像文件
- 当父级被隐藏并读取子项的css时,防止下载背景图像
- “未捕获的类型错误:无法读取未定义的属性'嵌入'”在 pdfMake pdf 引擎中使用自定义图像时
- JS读取图像并显示
- 未捕获的类型错误:无法读取图像上传的空错误的属性“addEventListener”
- 是否可以将图像读取到img标签中,并输入=“”;文件”;
- 在拖放过程中从外部远程图像读取URL数据
- 使用javascript从图像读取条形码
- 从图像读取透明像素
- 使用php或javascript从单个图像读取多个条形码