最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to pick(choose) multiple images using camera API at the same time in phonegap? - Stack Overflow

programmeradmin0浏览0评论

How to choose or pick multiple images at the same time in phonegap camera API when using Camera.DestinationType.FILE_URI. I am able to pick only one images at a time. I am able to pick multiple files(including txt,pdf..) in sdcard using this. So i want same like for images.

navigator.camera.getPicture(function(imageData) {
window.resolveLocalFileSystemURI(imageData, function(fileEntry) {
            fileEntry.file(function(fileObj) {
                    }, onFail, {
    quality : 50,
    destinationType : Camera.DestinationType.FILE_URI
});

My cordova version 3.3, Jquery Mobile 1.3.2.

Please suggest any plugins are available to do this.

How to choose or pick multiple images at the same time in phonegap camera API when using Camera.DestinationType.FILE_URI. I am able to pick only one images at a time. I am able to pick multiple files(including txt,pdf..) in sdcard using this. So i want same like for images.

navigator.camera.getPicture(function(imageData) {
window.resolveLocalFileSystemURI(imageData, function(fileEntry) {
            fileEntry.file(function(fileObj) {
                    }, onFail, {
    quality : 50,
    destinationType : Camera.DestinationType.FILE_URI
});

My cordova version 3.3, Jquery Mobile 1.3.2.

Please suggest any plugins are available to do this.

Share Improve this question edited May 23, 2017 at 10:32 CommunityBot 11 silver badge asked May 27, 2014 at 4:09 ViniVini 9771 gold badge15 silver badges34 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 3

Use this Cordova multiple image selector plugin to choose multiple image at a time. It is good plugin for choose multiple images.

Download the above plugin and copy paste the java classes. Set the required permission. Don't forget to copy the res folder just copy and paste in your res folder.

Inside assets/www create imagepicker.js copy and paste the dowloaded imagepicker.js

In your index.html set like this:

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="imagepicker.js"></script>

<script type="text/javascript">

    document.addEventListener("deviceready",onDeviceReady,false);

    function onDeviceReady(){

        window.imagePicker.getPictures(
                function(results) {
                    for (var i = 0; i < results.length; i++) {
                        alert('Image URI: ' + results[i]);

// read file type and size and file name like below(in ment)

/* window.resolveLocalFileSystemURI(results[i], function(fileEntry){
        fileEntry.file(function(fileObj) { 
            alert(fileEntry.name);
            alert(fileObj.size);
            alert(fileObj.type);
        }); 

    }, function (error) {
            alert('Error: ' + error);
        });*/
                    }
                }, function (error) {
                    alert('Error: ' + error);
                }
            );

    }
    </script>

Note: This should work only cordova 3.0 and above and android 4.0 and above

Open CameraLauncher.java file and replace these lines

String resizePath = getTempDirectoryPath() + "/resize.jpg";
this.callbackContext.success("file://" + resizePath + "?" + System.currentTimeMillis());

to

String resizePath = getTempDirectoryPath() + "/resize"+System.currentTimeMillis()+".jpg";
this.callbackContext.success("file://" + resizePath);

var x=0;
function onPhotoDataSuccess(imageURI)
{
    x++;
    // Unment to view the base64-encoded image data
    console.log(imageURI);
	alert(imageURI);
    // Get image handle
    //
    var y = 'smallImage'+x;
    var smallImage = document.getElementById(y);
    alert(smallImage);
	smallImage.src = "data:image/jpeg;base64," + imageURI;
    // Unhide image elements
    //
    smallImage.style.display = 'block';
  
    // Show the captured photo
    // The in-line CSS rules are used to resize the image
    //
    //var fso=new ActiveXObject("Scripting.FileSystemObject");
    //fso.CopyFile("data:image/jpeg;base64," + imageURI,"file:///storage/sdcard/DCIM/");
      
    alert(smallImage.src)
}

where x is the loop for doing the multiple image from camera as well as from photogallery

发布评论

评论列表(0)

  1. 暂无评论