将捕获的图像捕获到其他活动

时间:2013-05-19 17:04:48

标签: android android-camera

直升机,

我在活动A中有两个活动A和B.我有一个谷歌地图和一个按钮。按钮允许我拍照。拍照后我想在活动B中我可以编辑它并给出标题等等。

这是我在活动中的方法A单击一个按钮拍照

private void onTakeFoto() {


    Intent fotoIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

    startActivityForResult(fotoIntent, CAMERA_RESULT);

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK && requestCode == CAMERA_RESULT) {

        Intent intentB = new Intent(this, B.class);
        startActivityForResult(intentB , CAMERA_RESULT);

    }

}
活动B中的

我有一个imageView和EditText。我想在activView B中的imageView中显示捕获的图像。我该怎么做?有人可以给我一个提示吗?

感谢

在我的onActivityResult中我现在有了这段代码:

String res = null;
        String[] proj = {MediaStore.Images.Media.DATA};
        Cursor cursor =  getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj, null, null, null);
        if (cursor.moveToLast()) {
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            res =  cursor.getString(column_index);
                            cursor.close();
                Bitmap bitMap = BitmapFactory.decodeFile(res);
                m_currentImage.setImageBitmap(bitMap);

        }

正如我所说,我得到的是其他影像而不是被拍摄的影像。 sombody可以告诉我哪里出错了?

4 个答案:

答案 0 :(得分:0)

您可以在活动B类中启动相机并拍摄照片并在imageview.use上设置图片...

@Override
    protected void onActivityResult(int requestCode, int resultCode,
            Intent resultData) {
        super.onActivityResult(requestCode, resultCode, resultData);



        try {

            if ( resultData != null) {

                String[] projection = { MediaStore.Images.Media.DATA };
                Cursor cursor = managedQuery(
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        projection, null, null, null);
                int column_index_data = cursor
                        .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                cursor.moveToLast();

                uploadImagePath = cursor.getString(column_index_data);
                bitmapUploadImage = BitmapFactory.decodeFile(uploadImagePath);
                profileImageView.setImageBitmap(bitmapUploadImage);

答案 1 :(得分:0)

您可以通过putExtra

fotoIntent 活动的结果传递给新的 B 活动

答案 2 :(得分:0)

一个建议请在其他线程上解码图像,而不是在UI线程上解析。

答案 3 :(得分:0)

最后我找到了答案,

 if (resultCode == RESULT_OK && requestCode == CAMERA_RESULT) {

        Bitmap captureImage = (Bitmap) data.getExtras().get("data");
        m_currentImage.setImageBitmap(captureImage);
  }