0
Answered

Open Photo Gallery and receive an image

zaifulbahri kasim 4 months ago • updated by Vladimir Ovchinnikov 4 months ago 7

Hello,

I'm trying to use "IR.EVENT_RECEIVE_PHOTO_FROM_GALLERY" event to let the user install his own images ..
that's my code  :

IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetPopup("Popup 1").GetItem("Item 1"), function(){
      if(IR.OpenPhotoGallery()) {
           IR.AddListener(IR.EVENT_RECEIVE_PHOTO_FROM_GALLERY, 1, function(filename, filepath)  {
                IR.Log("Photo selected.\n Filename: " + filename + "\n Filepath: " + filepath);
               IR.GetPopup("Popup 1").GetItem("img").GetState(0).Image = filename; 
               IR.GetPopup("Popup 1").GetItem("img").GetState(0).ImageStretch = 1 ;
           });
       }
});

I did open the gallery and choose a photo,
And I suppose to get those arguments from that event :
the filename which is the photo name and filepath which is the path for my photo.
But what i really got is a standard name for any photo I choose which is image.png and standard path to the project folder : iRidium pro documents\Client\"ProjectName"\images\Image.png
I got those result every time i choose a photo , and it stores one image only

What should I do to make iridium store the received photos with their original names and  how could store more than one ??

And Regarding the IR.Camera method is it only for live streaming videos or can the user took photos and store it ??

Appreciate your help 

GOOD, I'M SATISFIED

good explanation..

Satisfaction mark by zaifulbahri kasim 4 months ago
+1
Under review

Hello.

At the moment, only a workaround is available - save the resulting file under a different name.

IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetPopup("Popup 1").GetItem("Item 1"), function(){
if(IR.OpenPhotoGallery()) {
IR.AddListener(IR.EVENT_RECEIVE_PHOTO_FROM_GALLERY, 0, function(filename, filepath){
IR.Log("Photo selected.\n Filename: " + filename + "\n Filepath: " + filepath);
IR.GetPopup("Popup 1").GetItem("Item 2").GetState(0).Image = filename;
IR.GetPopup("Popup 1").GetItem("Item 2").GetState(0).ImageStretch = 1;
var photoName = "photo_" + new Date().getTime().toString() + ".png";
IR.RenameFile("images/" + filename, "images/" + photoName);
});
}
});

Thanks , It works ..

that's my final code: 

function openGallery() {
      IR.OpenPhotoGallery();
}

IR.AddListener(IR.EVENT_RECEIVE_PHOTO_FROM_GALLERY, 0, function(filename, filepath){
            var photoName = "photo_" + new Date().getTime().toString() + ".png";
            IR.RenameFile("images/" + filename, "images/" + photoName);
            IR.GetPopup("Popup 1").GetItem("img").GetState(0).Image = photoName;
            IR.GetPopup("Popup 1").GetItem("img").GetState(0).ImageStretch = 1;
});

Hello.

Good. Perhaps your code will be useful to someone else who will have the same question.

Do you have any more questions?

Yes I hope ..

Still my question regarding the camera , is it possible for a user to take photo from the mobile camera and store it, or this method  IR.Camera is only for video streaming ?

Appreciate your help

+2

Hello.

This method is for video streaming only. There is a way to get an image from the stream, through undocumented functions. See attached example.

Base64Image.irpz