繁体   English   中英

如何将编码的jpeg图像保存到Java BlackBerry中的文件

[英]How to save an encoded jpeg image to file in Java BlackBerry

我正在为BlackBerry开发一个应用程序,以使用相机拍摄图像。 我几乎拥有所有必需的代码,但是我想知道如何将编码的jpeg图像保存到SD卡。 图像使用EncodedImage.createEncodedImage()函数进行编码。

您将需要获取图像的字节,然后使用OutputStream将其写入磁盘。 像这样

    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){

        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM