简体   繁体   English

将内置相机拍摄的图片设置为ImageView

[英]setting picture captured by built-in camera into an ImageView

in my app im 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. 所以我应该添加什么代码将图片设置为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();
// ...
}
}

Thanks in advance 提前致谢

Add a button and an ImageView to your main layout. 在主布局中添加一个按钮和一个ImageView。 When you click the button, first intent.putExtra to specify where the image will be stored, then start the camera intent. 当您单击按钮时,首先是intent.putExtra以指定图像的存储位置,然后启动相机的意图。 In your onActivityResult, if the resultCode comes back 0 that means the user accepted the picture. 在您的onActivityResult中,如果resultCode返回0,则表示用户接受了图片。 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中设置图像位图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM