在Android中使用摄像头捕获的图像 [英] capturing image using camera in Android

查看:117
本文介绍了在Android中使用摄像头捕获的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜计算器的朋友,
我需要在使用相机拍照和羚牛的图片后,进入下一个活动不显示的第一个活动。并在ImageView的显示。
下面是我的应用程序的流程

Hi stackoverflow friends, I need to take a picture using camera and after takin the picture go to next activity without showing the first activity. And display it in an imageview. Below is the flow of my application

第一活动 - >有相机键intent->进入下一个活动(不显示的拳头活动)活动 - 二>有我需要显示的ImageView图像。

first activity-> there is button for camera intent->go to the next activity(without showing the fist activity) second activity->there i need to show the image in imageview.

我看到了很多的摄像头意图没有人举例说明如何去到下一个活动没有表现出第一和第二的ImageView的显示出来。

I saw a lot of examples of camera intent nobody explains how to go to the next activity without showing the first and display it in imageview of second.

而在ImageView的反复显示图像出现的任何问题outofmemeory?

Any outofmemeory problem occurs while displaying images in imageview repeatedly?

在此先感谢

推荐答案

在第一项活动:

 Button b=(Button)findViewByid(R.id.button);
 b.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
    doTakePhotoAction();

    }
}); 
    private void doTakePhotoAction() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
    "pic_" + String.valueOf(System.currentTimeMillis()) + ".jpg"));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mUri);

try {
    intent.putExtra("return-data", true);
    startActivityForResult(intent, CAMERA_RESULT);
       // finish();
} catch (ActivityNotFoundException e) {
    e.printStackTrace();
}
}

 protected void onActivityResult(int requestCode, 
    int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
    return;
}
if (requestCode == CAMERA_RESULT) {
    Intent intent = new Intent(this, nextimage.class);
    // here you have to pass absolute path to your file
    intent.putExtra("image-path", mUri.getPath());
    intent.putExtra("scale", true);
    startActivity(intent);
        finish();
}
}

在nextimage.class你可以设置一个图像视图,然后从putExtra获得的ImagePath并将其放置在ImageView的。

In nextimage.class you can set one image view and get the imagepath from putExtra and place it in imageview.

  String mImagePath = extras.getString("image-path");
  Bitmap mBitmap = getBitmap(mImagePath);
   private Uri getImageUri(String path) {
return Uri.fromFile(new File(path));
}

private Bitmap getBitmap(String path) {
Uri uri = getImageUri(path);
InputStream in = null;
try {
    in = mContentResolver.openInputStream(uri);
    return BitmapFactory.decodeStream(in);
} catch (FileNotFoundException e) {
    Log.e(TAG, "file " + path + " not found");
}
return null;
}

放置在imageview.you在secondActivity创建imageview的位图。

place the bitmap in the imageview.you have to create imageview in secondActivity.

这篇关于在Android中使用摄像头捕获的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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