09-09-2011 02:40 PM
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/
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.
09-10-2011 12:10 AM
You can use FileConnection class for reading and writing to the 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);