tags:

views:

51

answers:

1

Hi I have an application that loads all the images of a folder in a canvas, vertically. Like thumbnails. These folders have usually more than 20 images, around 1mb sometimes even 2. I created a class called Index, that extend canvas.

I managed to load all the images and resize them to the proper size (the original size is around 1280x1985, yeah they are quit big. But it takes too long, and I think I know why but I dont know how fix it or do it better.

public void loadImages(){
        System.out.println("Loading Images");
        List<String> imageList = new ArrayList<String>();
        imageList = listDirImages(this.strDir);
        int listSize=imageList.size();
        for(int i=0;i<listSize;i++){
            System.out.println(imageList.get(i));
            Image sourceImage;
            System.out.println(strDir.concat("/".concat(imageList.get(i))));
            try {
                sourceImage = new Image(getDisplay(),strDir.concat("/".concat(imageList.get(i))));
                //sourceImage[i] = new Image(getDisplay(),strDir.concat("/".concat(lsImagenes.get(i))));
            }catch(Exception e){
                System.out.println(e);
                //band=1;
            }
        }
    }

This function uses the directory, then it calls to a function to list all the images. It lists all the images. The original code was different but i tried to eliminate the code to see where it is taking so long. Original sourceImage was an array of images (I dont know if that is better), and I resized the images creating new ones, but it took longer to create them.

with 25 images it takes almost 45 seconds to load this part, I know the problem is that i am loading the full image, and they are quite heavy. Is there a way to load them directly to a thumbnail? Some folders have around 80 pages, that is like 2 minutes. (For one part I think i have to this as thread, so the whole program could run other things while it is loading the index.

A: 

You need thumbnails to be pre-build on the server and just load them with the javascript. Even if there is a way to load images directly in thumbnails the client will still download the full size image to create the thumbnail and this is not good for the network bandwidth.

SileNT
It is not javascript, it is not even a web app or client server app. It is a local program on my machine.
Juan Diego