通过设置内置摄像头拍摄的画面成为一个ImageView的 [英] setting picture captured by built-in camera into an ImageView

查看:207
本文介绍了通过设置内置摄像头拍摄的画面成为一个ImageView的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用我打电话是内置摄像头捕捉的画面,但我想那画面设置成以下的成像图是code。还等什么code,我应该给它添加设置图片为ImageView的。

in my app i m calling built in camera for capturing picture but i want to set that picture into an image view following is the code . so what code should i add to it to set the picture into imageview.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    startActivityForResult(intent, 0);


}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK && requestCode == 0) {
String result = data.toURI();
// ...
}
}

在此先感谢

推荐答案

添加一个按钮和一个ImageView的到你的主布局。当您单击按钮,第一intent.putExtra来指定图像将被存储,然后启动相机意图。在你的onActivityResult,如果结果code回来0,这意味着用户接受了图片。在这种情况下,去抓住从你指定为意图的一个额外的路径图像。从创建的路径指定的文件位图,然后设置位图图像在ImageView的。

Add a button and an ImageView to your main layout. When you click the button, first intent.putExtra to specify where the image will be stored, then start the camera intent. In your onActivityResult, if the resultCode comes back 0 that means the user accepted the picture. In this case, go grab the image from the path you specified as an extra of the intent. Create a bitmap from the file specified by the path, then set the image bitmap in your ImageView.

这篇关于通过设置内置摄像头拍摄的画面成为一个ImageView的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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