图像捕获和活动中的显示

时间:2012-05-15 06:25:38

标签: android

我有一项活动A.从A开始活动B.在活动B中,我捕获了设备中存在相机的图像,并在活动结束时返回活动A.此活动必须显示捕获的图像。如何完成这项任务?在版本2.3.3上运行...看了Capture Image from Camera and Display in Activity,但是相同的NullPointerException ...在LG设备上运行。

1 个答案:

答案 0 :(得分:0)

您可以使用intent.putExtras方法将捕获的图像的URL从活动B传递到活动A.

参考Passing string array between android activities

捕获图像请参考下面的代码

public class Camera extends Activity 
{
     private static final int CAMERA_REQUEST = 1888;
     private String selectedImagePath;
     WebView webview;
     String fileName = "capturedImage.jpg";
     private static Uri mCapturedImageURI; 

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
            webview=(WebView)findViewById(R.id.webView1);
    }

    public void TakePhoto()
    {   
            ContentValues values = new ContentValues();  
            values.put(MediaStore.Images.Media.TITLE, fileName);  
            mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
            Intent cameraIntent = new Intent(ACTION_IMAGE_CAPTURE);
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI); 
            startActivityForResult(cameraIntent, CAMERA_REQUEST);
    }       
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        if (resultCode == RESULT_OK)
            {
              if (requestCode == CAMERA_REQUEST) 
              { 
                selectedImagePath = getPath(mCapturedImageURI);
                 //Save the path to pass between activities
              }
            }
    }

    public String getPath(Uri uri) {
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }

}