2011-05-24 109 views
0

我正在研究一個應用程序,該應用程序會使用我的相機拍攝一張照片並將其顯示在我的圖像視圖佈局中。因此,任何人都可以告訴我如何訪問拍攝的最新照片並顯示它。顯示在android中的圖像視圖佈局中拍攝的最新圖片

+0

多遠你有這麼遠嗎?你有什麼確切的問題? – Jodes 2011-05-24 07:48:56

+0

如何通過修改日期來識別圖片 – 2011-05-26 13:36:52

回答

0

我得到了解決,如果任何人有同樣的問題ü可以參考這個

public void click1(View v){ 
    //define the file-name to save photo taken by Camera activity 
    capturedImageFilePath=null; 
    fileName = System.currentTimeMillis()+""; 
    //create parameters for Intent with filename 
    ContentValues values = new ContentValues(); 
    values.put(MediaStore.Images.Media.TITLE, fileName); 
    values.put(MediaStore.Images.Media.DESCRIPTION,"Image capture by camera"); 
    //imageUri is the current activity attribute, define and save it for later usage (also in onSaveInstanceState) 
    imageUri = getContentResolver().insert(
      MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); 
    //create new Intent 
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); 


    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); 

} 
@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) { 
     if (resultCode == RESULT_OK) { 
      //use imageUri here to access the image 
      String[] projection = { MediaStore.Images.Media.DATA}; 
       Cursor cursor = managedQuery(imageUri, projection, null, null, null); 
       int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
       cursor.moveToFirst(); 
       capturedImageFilePath = cursor.getString(column_index_data); 
       imageFile = new File(capturedImageFilePath); 
       if(imageFile.exists()){ 
        Bitmap bm = BitmapFactory.decodeFile(capturedImageFilePath); 
        image.setImageBitmap(bm);} 
     } else if (resultCode == RESULT_CANCELED) { 
      Toast.makeText(this, "Picture was not taken", Toast.LENGTH_SHORT); 
     } else { 
      Toast.makeText(this, "Picture was not taken", Toast.LENGTH_SHORT); 
     } 
    } 
    } 
相關問題