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.READ_WRITE);
            if (!fconn.exists())
            OutputStream out = fconn.openOutputStream();
            PNGEncodedImage encodedImage = PNGEncodedImage.encode(bmp);
            byte[] imageBytes = encodedImage.getData();
        } catch (Exception e) {
            System.out.println(" Exception while saving Bitmap:: "+ e.toString());
       Dialog.inform("File has been saved succesfully in " + path );


StackTips provides programming tutorials, how-to guides and code snippets on different programming languages. Follow us on Twitter


Please note: We reserve the right to delete comments that contains snarky remarks, offensive or off-topic. To know more read our comments policy.