Android应用程序:如何使用摄像头和抓取图像的字节数? [英] Android application: how to use the camera and grab the image bytes?

查看:130
本文介绍了Android应用程序:如何使用摄像头和抓取图像的字节数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建为Android一个小应用程序的需要使用设备的摄像头的图像,并把关于它的顶部有一个PNG框架。这样,最终保存的图片将在它的上面,或帽子,或任何一个海滩。没有人有任何的示例程序与这种行为?

I'm trying to create a small app for Android that takes a picture using the device's camera and put's a PNG frame on top of it. This way the final saved picture will have a beach on top of it, or hats, or anything. Does anyone have any sample programs with this behavior?

推荐答案

有一个在SDK文档上使用图像捕捉意图的here

Have a look at the SDK documentation on using the image capture intent here.

我开始我的图像捕捉的意图是这样的:

I start my image capture intent like this:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

CAPTURE_IMAGE_ACTIVITY_REQUEST_ code是在我的活动一个私有成员:

CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE is a private member in my activity:

private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;

然后从相机使用以下的onActivityResult处理得到的字节数组回:

Then get the byte array back from the camera by using the following onActivityResult handler:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {        
    if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            Bitmap bmp = (Bitmap) data.getExtras().get("data");
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byte[] byteArray = stream.toByteArray();

            AddImage(byteArray);

        } else if (resultCode == Activity.RESULT_CANCELED) {
            // User cancelled the image capture
        } else {
            // Image capture failed, advise user
        }
    }               
}

之后,你可以做在图像上你想要的所有处理。

After that you can do all the processing you want on the image.

这篇关于Android应用程序:如何使用摄像头和抓取图像的字节数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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