gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 15:55:26 24 4
gpt4 key购买 nike

我正在开发一款用于黑莓手机的应用程序,用于使用相机拍摄图像。我几乎拥有所有必要的代码,但我想知道如何将编码的 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){

}
}

关于java - 如何在 Java BlackBerry 中将编码的 jpeg 图像保存到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5163413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com