Important! A new Community experience launched on September 26, 2017. Read more about it here or continue to Base Camp.
Voting: 
Vote up!
0 Votes
1 Replies
Answered

display a saved image

Question asked by Roelof Koelewijn on Mar 02, 2017 08:18 EST

Hi I'm struggeling to get the image I saved to the filesystem displayed on the image widget, anybody who knows how to do this? My code: function frmPhotos_oncapture_photo(camera){      try{          var lMediaName = "foto" + "-" + 1;          // set photo            var resizeimage = kony.image.createImage(camera.rawBytes);            kony.print("### image width: " + resizeimage.getImageWidth());            resizeimage.compress(0.7);            var base64FromImage = kony.convertToBase64(resizeimage.getImageAsRawBytes());            //Save photo to file          //determin path for data storage            var path = kony.io.FileSystem.getDataDirectoryPath();            //create the file in directory photos            var myfile = kony.io.FileSystem.getFile(path + "/photos/" + lMediaName + ".jpg");            myfile.createFile();          //add the data to the file            var imgData =  base64FromImage;          //alert("FILE NAME >>>>>>>>"+myfile.name);          //alert("IS READABLE >>>>>>>"+myfile.readable);          //alert("IS WRITABLE >>>>>>>"+myfile.writable);          var dataAdded = myfile.write(imgData,false);          //alert("IS DATA ADDED >>>>>>>"+dataAdded);           //get the filelist of the directory photos            var photoDirectory = kony.io.FileSystem.getFile(path+"/photos/");            var fileList = photoDirectory.getFilesList();            //alert(fileList.item(0));            var getfile = kony.io.FileSystem.getFile(fileList.item(0).fullPath);            getfile.createFile();            frmPhotos.imgPhoto.rawBytes = getfile;      } }

Kony Answered Certificate
Vote up!
0 votes
Vote down!

found the solution by doing:

var imgData = resizeimage.getImageAsRawBytes(); //the data you write has to be rawbytes

 var dataAdded = myfile.write(imgData,false);

Answered by: Mar 16, 2017 03:27 EDT