2011-12-18 3 views
0

사진을 찍어 SD 카드에 저장할 수있는 Android 앱을 작성 중입니다. 나중에 GridView에 그림을 표시해야하며 사용자가 선택할 수 있습니다. 이것은 내 그림을 저장하는 코드입니다.저장된 이미지를 mediastore에 추가하고 축소판을 생성하는 방법은 무엇입니까?

Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() { 
     @Override 
     public void onPictureTaken(byte[] data, Camera c) {   
      currentPictureName = (String) getResources().getText(R.string.username) 
        + System.currentTimeMillis() + ".jpg"; 

      FileOutputStream outStream = null; 
      try { 
       outStream = new FileOutputStream(sdcardPath + currentPictureName); 
       outStream.write(data); 
       outStream.close(); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } finally { 
       mCamera.startPreview(); 
      } 
     } 

그러나 저장된 이미지에는 GridView에 축소판 그림이 표시되지 않습니다. 저장 한 모든 이미지의 축소판 그림을 자동으로 생성하고 나중에 액세스 할 수 있도록 MediaStore에 모든 것을 추가하려면 어떻게합니까?

답변

0

발견 된 this. 이 작업은 완벽하게 정상적으로 작동하고 모든 미리보기 이미지가 자동으로 생성됩니다.

1

scanFile() 기능을 사용해보세요.

에서 onCreate에서 당신과 같이 미디어 스캐너에 연결할 수

private class ImageScannerClient implements MediaScannerConnection.MediaScannerConnectionClient { 

     @Override 
     public void onMediaScannerConnected() { 
      // Start scanning files you have in a que 
     } 

     @Override 
     public void onScanCompleted(String path, Uri uri) { 
      // Run some code, then maybe initiate scan of next file in que 
     } 

} 

당신은 미디어 스캐너 연결 클라이언트를 구현해야합니다

// Connect to media scanner 
    this.mediaScanner = new MediaScannerConnection(getApplicationContext(), new ImageScannerClient()); 
    this.mediaScanner.connect(); 

을 그리고 다른 시점에서 당신은 가야에 파일을 추가해야합니다 또는 스캔 할 대상

+0

감사합니다.이 또한 http://www.mail-archive.com/[email protected]/msg63884.html 시도 중입니다. –

+0

'scanFile()'도 자동으로 미리보기 이미지를 생성합니까? –

+0

예, 그렇게 생각합니다. –

관련 문제