拍照并将它传递给另一个活动 [英] Take photo and pass it to another activity

查看:114
本文介绍了拍照并将它传递给另一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建简单的应用程序在那里我可以拍张照片并通过照片和密切的相机后,并通过照片到另一个活动。我不知道我该怎么开始。你能给我一些例子我该怎么办,在简单的方法?

I want to create simple app where I can take a photo and pass this photo and after that close camera and pass this photo to another activity. I don't know how can I start. Can you give me some examples how can I do that in easy way?

推荐答案

要捕捉图像:
    INT CAMERA_REQUEST = 1888;

To capture image: int CAMERA_REQUEST = 1888;

    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    cameraIntent.putExtra("putSomething", true);
    startActivityForResult(cameraIntent, CAMERA_REQUEST);

获取图像焕的照片通过捕获的onActivityResult:

Get image whan photo captured through onActivityResult:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {  
        this.photo = (Bitmap) data.getExtras().get("data");
    }
}

您可以通过将照片转换成字节数组传递照片并通过意图

You can pass photo by converting photo into byte array and pass through intent

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    photo.compress(Bitmap.CompressFormat.PNG, 90, stream);
    byte[] image = stream.toByteArray();

    Intent intent = new Intent(this, YourActivity.class);
    intent.putExtra("photo", image);
    startActivity(intent);

这篇关于拍照并将它传递给另一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆