Get properties of Image programmatically / Make bitmap image from file located in any location -BlackBerry Development

Create Bitmap image as follows then

Bitmap _bitmap;
_bitmap=getBitmap("file:///SDCard/image.jpg");
int h=_bitmap.getHeight();
int w=_bitmap.getWidth();
Dialog.alert("height"+Integer.toString(h)+"width"+Integer.toString(w));

getBitmap image will be like this

public Bitmap getBitmap(String filepath)
{
    Bitmap bkBitmap = null;
    try {
             FileConnection fconn = (FileConnection)Connector.open(filepath );
             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;
}

No comments:

Post a Comment

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...