×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    50

    Using Tantalum to load filesystem Images

    I am trying to use Tantalum to efficiently load images from the filesystem. I am looking for some direction on how to do this. I have looked at the Picasa app. It uses StaticWebCache in conjunction with ImageCacheView to download and cache images. How would I do this for local filesystem images?

    Can I use StaticWebCache with a file:/// url? Do I need to use StaticCache instead? The StaticCache put() method, which I assume I would need to use to get an image from the memory card into the cache, has an Object parameter; how would I provide that object in the case of a filesystem image without first loading the image into memory?

    Any help on this would be greatly appreciated!

  2. #2
    Registered User
    Join Date
    Sep 2013
    Posts
    50

    Re: Using Tantalum to load filesystem Images

    Here's what I'm trying to do so far. A few problems already:

    1. It seems to require that the put be done on a background thread. So as soon as the readFully method is called for 4 of these 1.5 MB images, I get an out of memory error.

    2. I'm using LWUIT, but it seems like Tantalum only wants to add it to the cache as a LCDUI Image. If I have to convert that to LWUIT Image, is this defeating the purpose of using Tantalum?


    Code:
    public class Storage {
    
        public static StaticCache thumbnailCache;
        private static ImageCacheView imageCacheView;
        public static int size;
    
        public static void init(int size){
    
    
            if(thumbnailCache==null){
               Storage.size=size;
                imageCacheView =
                        PlatformUtils.getInstance().getImageCacheView();
    
    
                imageCacheView.setMaxSize(size,size);
                imageCacheView.setPreserveAspectRatio(true);
    
    
                try {
                    thumbnailCache=StaticCache.getCache('0',PlatformUtils.PHONE_DATABASE_CACHE,imageCacheView, null);
                } catch (FlashDatabaseException e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                }
    
            }
    
        }
    
        public static void setThumbnail(final String uri, final ImageGridButton b){
    
    
            try {
                FileConnection fileConn = (FileConnection) Connector.open(
                        "file:///" + uri.trim(), Connector.READ);
    
    
                DataInputStream fis = fileConn.openDataInputStream();
    
                byte[] arr = new byte[1572864];
                Log.v("Begin readFully");
                try{
                    fis.readFully(arr);
                }catch(EOFException e){
    
                }
    
                Log.v("End readFully");
    
                try {
                    Log.v("before put");
    
                    thumbnailCache.put(uri,new LOR(arr),imageCacheView,new Task() {
    
                        protected Object exec(Object o) throws CancellationException, TimeoutException, InterruptedException {
                            Log.v("exec");
    
    
    
                            javax.microedition.lcdui.Image lcduiImg = (javax.microedition.lcdui.Image)thumbnailCache.get(uri);
    
                            Image img = Image.createImage(lcduiImg);
    
    
                            Image subImage= img.subImage(1, 1, size-2, size-2, false);
                            b.image=img;
                            b.subimage=subImage;
    
                            b.setIcon(b.image);
                            b.setPressedIcon(b.image);
    
                            return null;
                        }
                    });
                } catch (FlashDatabaseException e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                }
    
            } catch (IOException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
    
    
        }
    }

Similar Threads

  1. How to use Tantalum library
    By arunkam in forum Mobile Java General
    Replies: 9
    Last Post: 2013-08-15, 13:52
  2. how to load and display images
    By prakashforum in forum Symbian C++
    Replies: 4
    Last Post: 2010-07-22, 20:38
  3. How to load images in 1st edition ?
    By pawelbrzez in forum Python
    Replies: 1
    Last Post: 2006-05-26, 19:32
  4. cannot load images to devices
    By zivgr in forum Mobile Java General
    Replies: 3
    Last Post: 2003-06-04, 07:35

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •