文件大小不能当图像从形象画册选用阅读 [英] File size not able to read when images is choosed from image album

查看:204
本文介绍了文件大小不能当图像从形象画册选用阅读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的PhoneGap应用(Android版本4.4.2),我需要选择图像格式的SD卡。在此我无法读取图像大小和名称。我的code是等。

 函数getSkiImage(ID,源){
    navigator.camera.getPicture(功能(imageURI){
        警报(imageURI);
        window.resolveLocalFileSystemURI(imageURI,功能(FileEntry的){
            警报(FileEntry的);
            fileEntry.file(功能(FileObj文件){
                警报(fileObj.size);            });
        });
//尝试这也
/*window.requestFileSystem(imageURI,0,功能(数据){
    警报(data.size);},失败); * /
},失败,{质量:50,
    destinationType:destinationType.FILE_URI,
    sourceType的:pictureSource.PHOTOLIBRARY});
}

在我的Andr​​oid设备(V 4.4.2)的专辑节目,如最近,驱动器,图像,画廊,......当从图库中选择图像,然后仅图像尺寸为getting..other比画廊图像的大小是不是能够得到..

所指向这一点,但没有获得成功。

科尔多瓦/ PhoneGap的照片文件大小

在PhoneGap的文档,他们说:


  

Android 4.4系统的只有:Android 4.4的推出了新的存储访问
  框架,使用户更方便地浏览和打开文件
  在所有的preferred文档存储供应商。科尔多瓦有
  尚未与这一新的存储访问架构完全集成。
  正因为如此,在Getpicture中()方法将不能正确地返回
  当用户从近期,驱动器,图像选择图片,
  或外部存储文件夹时,destinationType为FILE_URI。
  但是,用户将能够正确地选择任何图片,如果
  他们通过了画廊应用第一。潜在的解决方法
  这个问题都记录在这个计算器的问题。请参见
  CB-5398来追踪这个问题。


  
  

Android使用意图启动设备上的摄像机活动
  捕捉图像,而在低内存的手机,科尔多瓦活动
  可能会被杀死。在这种情况下,图像可能不会出现在
  科尔多瓦活动得以恢复。



解决方案

 <!DOCTYPE HTML>
< HTML和GT;
  < HEAD>
    <标题>捕获照片< /标题>    <脚本类型=文/ JavaScript的字符集=utf-8SRC =cordova.js>< / SCRIPT>
    <脚本类型=文/ JavaScript的字符集=utf-8>    VAR pictureSource; //图片来源
    VAR destinationType; //设置返回值的格式    //等待PhoneGap的与设备连接
    //
    document.addEventListener(deviceready,onDeviceReady,FALSE);    // PhoneGap的是随时可以使用!
    //
    功能onDeviceReady(){
        pictureSource = navigator.camera.PictureSourceType;
        destinationType = navigator.camera.DestinationType;
        getPhoto(pictureSource.PHOTOLIBRARY);
    }
    功能onPhotoURISuccess(imageURI){
      警报(imageURI);      变种largeImage =的document.getElementById('largeImage');      largeImage.style.display =块;
      largeImage.src = imageURI;
      window.requestFileSystem(LocalFileSystem.PERSISTENT,0,onFileSystemSuccess,RFAIL);
      window.resolveLocalFileSystemURI(imageURI,onResolveSuccess,失败);
    }    功能RFAIL(五){
        警报(E);
    }
    功能getPhoto(源){
      //从指定源中检索图像文件位置
      navigator.camera.getPicture(onPhotoURISuccess,onFail,{质量:50,
        destinationType:destinationType.FILE_URI,
        sourceType的:源});
    }
    功能onFileSystemSuccess(文件系统){
        的console.log(fileSystem.name);
    }
    功能bytesToSize(字节){
        变种尺寸= ['字节','的KB','MB','GB','结核病'];
        如果(字节== 0)返回N / A;
        变种I = parseInt函数(Math.floor(将Math.log(字节)/将Math.log(1024)));
        返回+''+尺寸Math.round(2字节/ Math.pow(1024,I))[我]
    };
    功能onResolveSuccess(FileEntry的){
        filenameofajax = fileEntry.name;        VAR efail =功能(EVT){
            的console.log(文件输入错误+错误code);
        };
        VAR赢=功能(文件){
            的console.log(文件);
            对于(文件变种I){
                警报(I ++文件[I]);
            }
            警报(bytesToSize(file.size));        };
        fileEntry.file(赢,efail);
    }
    功能efail(五){
        警报(ESA)
    }
    功能失效(五){
        警报(SA)
    }    //调用如果有什么不好的事情发生。
    //
    功能onFail(消息){
      警报('因为失败:'+消息);
    }    < / SCRIPT>
  < /头>
  <身体GT;
    <按钮的onclick =capturePhoto();>捕获照片< /按钮> < BR>
    <按钮的onclick =capturePhotoEdit();>捕获编辑照片及LT; /按钮> < BR>
    <按钮的onclick =getPhoto(pictureSource.PHOTOLIBRARY);肽从图片库< /按钮>< BR>
    <按钮的onclick =getPhoto(pictureSource.SAVEDPHOTOALBUM);>从相册和LT; /按钮>< BR>
    < IMG风格=显示:无;宽度:60像素,高度:60像素; ID =smallImageSRC =/>
    < IMG风格=显示:无; ID =largeImageSRC =/>
  < /身体GT;
< / HTML>

检查此

In my phonegap application(android version 4.4.2) i need to pick image form sdcard. In this i am unable to read the image size and name. My code is like.

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 }); 
}

In my android device(v 4.4.2) album shows like "Recent", "Drive", "Images","Gallery",...when select image from gallery then only the image size is getting..other than Gallery image size is not able to get..

refered this but not get success

Cordova/PhoneGap Photo File Size

In phonegap doc they say :

Android 4.4 only: Android 4.4 introduced a new Storage Access Framework that makes it easier for users to browse and open documents across all of their preferred document storage providers. Cordova has not yet been fully integrated with this new Storage Access Framework. Because of this, the getPicture() method will not correctly return pictures when the user selects from the "Recent", "Drive", "Images", or "External Storage" folders when the destinationType is FILE_URI. However, the user will be able to correctly select any pictures if they go through the "Gallery" app first. Potential workarounds for this issue are documented on this StackOverflow question. Please see CB-5398 to track this issue.

Android uses intents to launch the camera activity on the device to capture images, and on phones with low memory, the Cordova activity may be killed. In this scenario, the image may not appear when the Cordova activity is restored.

解决方案

<!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>

check this

这篇关于文件大小不能当图像从形象画册选用阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆