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

Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10
My Carrier: Fido

Saving image to Media Card

HI. This is a simple question, I've looked for answers and have found none.


I would like to download an image from a URL on our server (like so)


InputStream is = ConnectionClass.getInputStreamhttp://server.company.com/mws/graphics/blackberry/generic.png);


int length = is.available();



data = IOUtilities.streamToBytes(is);

Bitmap image = Bitmap.createBitmapFromBytes(data,0,data.



Now I have the Bitmap, how can I save it to a specified directory on the media card?? Then how can I access it later?? How do I turn it back into a Bitmap object??


Thanks a lot.

Posts: 123
Registered: ‎07-08-2011
My Device: Torch 9800, Bold 9700
My Carrier: Bell, Rogers

Re: Saving image to Media Card

You can use FileConnection class for reading and writing to the SDCARD.


(FileConnection) Connector.open("file:///SDCard/......");


read the data bytes. Create a Bitmap from the data and use JPEGEncodedImage  to create the jpeg from the bitmap data.



FileConnection f = (FileConnection) Connector.open("file://" + mypath);

            InputStream in = file.openInputStream();
            int avail = in.available();

            byte[] data = new byte[(int) f.fileSize()];

            Bitmap bitmap = Bitmap.createBitmapFromBytes(data, 0, data.length, 1);
            JPEGEncodedImage jpeg = JPEGEncodedImage.encode(bitmap, 100);


Berobo Inc.
Police Scanner Radio / Alarm Clock lets you listen to Police scanners in your area!
Please click the Like button to thank the user that has helped you and
please mark post as solved when you have found the solution to your problem.