Tutorials Blackberry Saving Bitmap Image in Blackberry File System

Saving Bitmap Image in Blackberry File System

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 );
    }
Total
0
Shares
Previous Post
j2me_tutorials_javatechig_featured_image

Playing audio from mobile file system in J2ME

Next Post
Blackberry Tutorials

Customizing Blackberry LabelField

Related Posts
By clicking “Allow All”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookie Notice
Allow All