Saving image in blackberry inside filesystem is typically the same process like Java ME. JSR 75 is used to open the file connection and then the bitmap need to be changed to encoded using blackberry built in PNGEncodedImage class. It represents the image encoded in the PNG format. The createEncodedImage used to create an instance of PNGEncoded Image and this method accepts a java byte array containing the encoding of an image as a input.It is available from Blackberry JDE 3.6 onwards.
Here is the code snapshot shows sample to save bitmap in file system.
private void saveBitmap(String path, Bitmap bmp) { try { FileConnection fconn = (FileConnection) Connector.open(path, Connector.READ_WRITE); if (!fconn.exists()) fconn.create(); OutputStream out = fconn.openOutputStream(); PNGEncodedImage encodedImage = PNGEncodedImage.encode(bmp); byte[] imageBytes = encodedImage.getData(); out.write(imageBytes); out.close(); fconn.close(); } catch (Exception e) { System.out.println(" Exception while saving Bitmap:: "+ e.toString()); e.getMessage(); } Dialog.inform("File has been saved succesfully in " + path ); }
