Teo
Teo

Reputation: 1

How to save an encoded jpeg image to file in Java BlackBerry

I'm developing an app for BlackBerry to take images with the camera. I have almost all necessary code, but I'm wondering how to save an encoded jpeg image to SD Card. The image is encoded with EncodedImage.createEncodedImage() function.

Upvotes: 0

Views: 1274

Answers (1)

Greg McGowan
Greg McGowan

Reputation: 1360

You will need to get the bytes of the image and then use an OutputStream to write them to disk. Something like this

    FileConnection imageFile = null;;
    byte[] rawData = encodedImage.getData();
    try{
        //You can change the folder location on the SD card if you want
        imageFile = (FileConnection) Connector.open("file:///SDCard/BlackBerry/images"+filename);
        if(!imageFile.exists()){
            imageFile.create();
        }

        //Write raw data
        OutputStream outStream = imageFile.openOutputStream();
        outStream.write(rawData);
        outStream.close();
        imageFile.close();
    } catch(IOException ioe){
        //handle exception
    } finally {
        try{
            if(imageFile != null){
                imageFile.close();
            } 
        } catch(IOException ioe){

        }
    }

Upvotes: 1

Related Questions