Get Bitmap image from file located in SD Card-BlackBerry

In many GUI design purposes we need to get bitmap images from existing files in memory card.This method returns bitmap image of the given file name file must be located in path “file:///SDCard/Themes/

public Bitmap getBitmap(String fileName)
    {
        Bitmap bkBitmap = null;
        try {
                 FileConnection fconn = (FileConnection)Connector.open("file:///SDCard/Themes/"+fileName );
                 InputStream input = null;
                 input = fconn.openInputStream();     
                 int available = 0;
                 available = input.available();
                 int fSz = (int)fconn.fileSize();
                 byte[] data = new byte[fSz];            
                 input.read(data, 0, fSz);
                 EncodedImage image = EncodedImage.createEncodedImage(data,0,data.length);
                 bkBitmap = image.getBitmap();               
            }
        catch(Exception e)
            {
            }
        return bkBitmap;
    }

1 comment:

  1. Hi Sanjeewa,

    I was try this code. I get problem with the image. Image is fixed size in my screen, wont to scroll right/left. Image just scroll to up and down.
    I'm sorry about my english. Thank'sfor you'r help.

    Mugiono

    ReplyDelete

Empowering the Future of API Management: Unveiling the Journey of WSO2 API Platform for Kubernetes (APK) Project and the Anticipated Alpha Release

  Introduction In the ever-evolving realm of API management, our journey embarked on the APK project eight months ago, and now, with great a...