Uploading Photos from a Device Gallery

In iRidium Studio now can use any image from the gallery of your device in a project.


iRidium Studio gives you opportunity to use any images from the gallery of your device (Smartphone, tablet).


IR.OpenPhotoGallery() command opens the gallery of a device.
IR.EVENT_RECEIVE_PHOTO_FROM_GALLERY is a new event that works when an image is received from the gallery. On the basis of these commands you can create a script logics for your needs.




Example of command use:

IR.AddListener(IR.EVENT_START, 0, function(){

   if ( ! IR.OpenPhotoGallery() ) {

// If the photo gallery is not supported on the platform, write a message to the log.
   IR.Log( "is not supported on current platform" );

   } else {

   // Otherwise subscribe to the event of receiving an image from the gallery

     IR.AddListener( IR.EVENT_RECEIVE_PHOTO_FROM_GALLERY, 0, function( name ) {

     // the incoming name of a picture is always the same - Image.png. Rename the received picture to be able to use several images.

 //  make"photoName" variable and give it a value with the new image name. It is formed from the words "photo_", time in ms, received with the help  of  Date( ).getTime( ) commands and transferred into a line and add ".png" at the end of the name

var photoName = "photo_" + new Date( ).getTime( ).toString( ) + ".png";
     
// substitute the initial name with our variable.
IR.RenameFile("images/" + name, "images/" + photoName);

// put this picture on the page open at the moment
IR.CurrentPage.GetState(0).Image = photoName;
});
}
});

Example of a ready project for iPad This example how to select abd install a gallery image on the current page when a button is pressed.



When a project is launched on iPhone, the standard gallery offers to cut an image, as a result only part of page is covered with an image.

Is this article helpful for you?