2011-03-02 7 views
0

저는 카메라로 이미지를 찍을 수있는 BlackBerry 용 앱을 개발하고 있습니다. 거의 모든 필요한 코드가 있지만 SD 카드에 인코딩 된 jpeg 이미지를 저장하는 방법이 궁금합니다. 이미지는 EncodedImage.createEncodedImage() 함수로 인코딩됩니다.인코딩 된 jpeg 이미지를 Java Java 파일로 저장하는 방법

답변

1

이미지의 바이트를 가져 와서 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){ 

     } 
    }