Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 21st, 2012  |  syntax: None  |  size: 2.02 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ImageView using image stored at Titanium.Filesystem.applicationDataDirectory displays placeholder, not image
  2. var image = event.media // from camera success
  3.  
  4. var filename = new Date().getTime() + "-ea.jpg";
  5.  
  6. bgImage = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, filename);
  7.  
  8. bgImage.write(image);
  9.        
  10. var db = Titanium.Database.open('photoDB');
  11. try{
  12.     db.execute('INSERT INTO stored (image) VALUES (?)', bgImage.nativePath);
  13. } catch(e) {
  14.     alert(e.message);
  15. }
  16.  
  17. db.close();
  18.        
  19. imageArray = [];
  20. images = [];
  21.  
  22. var db = Titanium.Database.open('photoDB');
  23. var dbrows = db.execute('select id, date, image from stored order by date asc');
  24.  
  25. while (dbrows.isValidRow()) {
  26.  
  27.     imageArray.push({
  28.         image:dbrows.fieldByName('image')
  29.     });
  30.  
  31.     dbrows.next();
  32. }
  33.  
  34. dbrows.close();
  35.  
  36. // loop thru and display images
  37. for (var i = 0; i < imageArray.length; i++){
  38.  
  39.     var pushleft = (i % 4) * 75; // tile from left
  40.     var pushtop = Math.floor(i/4) * 96; // determine how far from top
  41.  
  42.     var file = Titanium.Filesystem.getFile(imageArray[i].image);
  43.  
  44.     images[i] = Ti.UI.createImageView({
  45.         image: imageArray[i].image, // path to image at applicationDataDirectory
  46.         width: 75,
  47.         height: 96,
  48.         left: pushleft + 5, // logic for positioning
  49.         top: pushtop + 5, // logic for positioning
  50.         store_id: imageArray[i].id
  51.     });
  52.  
  53.     win.add(images[i]);
  54. }
  55.        
  56. // Create a file name
  57. var filename = new Date().getTime() + "-ea.jpg";
  58.  
  59. // Create the file in the application directory
  60. bgImage = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, filename);
  61.  
  62. // Write the image to the new file (image created from camera)
  63. bgImage.write(image);
  64.        
  65. images[i] = Ti.UI.createImageView({
  66.     image: Titanium.Filesystem.applicationDataDirectory + Ti.Filesystem.separator + imageArray[i].image, // path to image at applicationDataDirectory
  67.     width: 75,
  68.     height: 96,
  69.     left: pushleft + 5, // logic for positioning
  70.     top: pushtop + 5, // logic for positioning
  71.     store_id: imageArray[i].id
  72. });