Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 13
Registered: ‎05-12-2010
My Device: Curve
My Carrier: GSM

Reading Image from SD Card is very Slow

Hi to All,

 

          I developed one application which will display the advertisment banner images in all the screen navigation. So i kept all the images in the SD Card, the size is nearly 200MB. And While reading images from the SD Card is very slow, its taking more time to display the image in the screen. I am having one custom control to scroll the image to view its full size, and the control is taking more time to scroll. I used the following code to read the images from SD Card,

 

        FileConnection connection=null;
        byte[] byteArray=null;
        EncodedImage image;
        Bitmap bitmap=null;
        try
        {
            connection=(FileConnection)Connector.open(filePath);
            if(connection.exists())
            {
                byteArray=new byte[(int)connection.fileSize()];
                InputStream inputStream=connection.openInputStream();
                inputStream.read(byteArray);
                inputStream.close();
                image=EncodedImage.createEncodedImage(byteArray, 0, -1);
                bitmap= image.getBitmap();
            }
            connection.close();
        }
        catch(Exception e)
        {
            System.out.println("Exception "+e.toString());
        }      
        return bitmap;

 

All the Images are PNG images. I do not know exactly what is problem, if anybody knows the solution please help me.

 

Thanks and Regards,

Rajapandian.K

Developer
Posts: 16,637
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Reading Image from SD Card is very Slow

maybe you should install a few GB more RAM in your BB :smileywink:

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 19,621
Registered: ‎07-14-2008
My Device: Not Specified

Re: Reading Image from SD Card is very Slow

Just a thought, is it the reading or the decoding taking the time?

 

Timestamp this processing and let us know.  Here is where I would timestamp:

 

long startTime = System.currentMillis(); 

          connection=(FileConnection)Connector.open(filePath);
            if(connection.exists())
            {
long getMemoryTime = System.currentMillis();

                byteArray=new byte[(int)connection.fileSize()];
long openDataTime = System.currentMillis();

                InputStream inputStream=connection.openInputStream();
long readTime = System.currentMillis();

                inputStream.read(byteArray);
long closeTime = System.currentMillis();

                inputStream.close();
long encodeTime = System.currentMillis();

                image=EncodedImage.createEncodedImage(byteArray, 0, -1);
long bitmapTime = System.currentMillis();

                bitmap= image.getBitmap();
System.out.println(all the time differences.);

            }
            connection.close();

 

Also can't you convert straight to a Bitmap?

 

Finally do you need to get a new one each time, or do you reuse the same one.  I'm sure you could something like have one ready, then when you use it, start a background Thread to update it to the next one.  That way it will be loading the second one while the first one is being watched.