我怎样才能捕捉图像并保存在我的活动图像视图? [英] How can i capture the image and save in the image view in my activity?

查看:133
本文介绍了我怎样才能捕捉图像并保存在我的活动图像视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在,我有一个按钮和图像查看活动一。当我点击按钮,它应该加载摄像头,并保存图像在图像中view.Can任何人为此提供code。

I have an activity A in which i have a button and an image view. When i click the button it should load the camera and save the image in the image view.Can anyone provide code for this.

先谢谢了!

推荐答案

见下文code ..它可以帮助你。

see below code.. it may help you.

把这两个线路在你点击按钮。

put this two line in your button click..

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, 0);

在创建这个方法,你code ..

create this method in you code..

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

         if (requestCode == 0 && resultCode == RESULT_OK) {
            if (data != null) {

                photo = (Bitmap) data.getExtras().get("data");

                add_image.setImageBitmap(photo); /* this is image view where you want to set image*/

                Log.d("camera ---- > ", "" + data.getExtras().get("data"));


            }
        }
    }

.............................. ...........................................

...........................................................................................

给你LastImageID采取相机。这仅仅是额外的code你想孔图像,然后它的使用,全给你。

below code give you LastImageID taken by camera. this is just extra code you want hole image then its use-full to you.

.............................. .........................................

........................................................................................

private String getLastImageId() {
        final String[] imageColumns = { MediaStore.Images.Media._ID,
                MediaStore.Images.Media.DATA };
        final String imageOrderBy = MediaStore.Images.Media._ID + " DESC";
        Cursor imageCursor = managedQuery(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imageColumns,
                null, null, imageOrderBy);
        if (imageCursor.moveToFirst()) {
            int id = imageCursor.getInt(imageCursor
                    .getColumnIndex(MediaStore.Images.Media._ID));
            String fullPath = imageCursor.getString(imageCursor
                    .getColumnIndex(MediaStore.Images.Media.DATA));

            imageCursor.close();
            return fullPath;
        } else {
            return "no path";
        }
    }

这篇关于我怎样才能捕捉图像并保存在我的活动图像视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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