2011-05-24 68 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); 
     } 
    } 
    } 
相关问题