2013-10-04 98 views
3

我正在開發一個Android應用程序,該應用程序捕獲圖像,然後使用opencv函數對其進行處理,然後返回生成的圖像並將其顯示在圖像視圖中。如何暫時保存拍攝的圖像以便處理?在Android上捕獲臨時圖像保存圖像

public class Camera extends Activity 
{ 
    ImageView imgview; 
    Bitmap Bmp; 
    final static int cameraData=0; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.camera); 
     imgview= (ImageView) findViewById(R.id.imgview); 
     Intent i=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 

     startActivityForResult(i,cameraData); 
    } 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     // TODO Auto-generated method stub 
     super.onActivityResult(requestCode, resultCode, data); 
     if(resultCode == RESULT_OK) 
     { 
      Bundle extras=data.getExtras(); 
      Bmp=(Bitmap)extras.get("data"); 
      imgview.setImageBitmap(Bmp); 
     } 
    } 
} 

回答

2

您可以將位圖保存到應用程序的緩存文件夾,如下所示:

String destFolder = getCacheDir().getAbsolutePath(); 

FileOutputStream out = new FileOutputStream(destFolder + "/myBitamp.png"); 
bmp.compress(Bitmap.CompressFormat.PNG, 100, out); 
+0

感謝...但我怎麼能保存到了文件後,處理它? – QAIS

+0

你想用這個文件做什麼? –

+0

將圖像轉換爲灰度... – QAIS