【问题标题】:Android. How to capture image from camera and save it to imageView? [duplicate]安卓。如何从相机捕获图像并将其保存到 imageView? [复制]
【发布时间】:2015-07-01 13:11:42
【问题描述】:

我需要从相机捕获图像并将其存储到 imageView。

Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, 0);

和onActivityResult方法:

Uri selectedImage = imageReturnedIntent.getData();
mPhoto.setImageURI(selectedImage);

【问题讨论】:

  • 那是什么问题??请清楚你想要什么

标签: java android camera android-camera


【解决方案1】:

就这样试试吧:

此代码用于从相机捕获图像并显示在 imageview 中。

public class MainActivity extends ActionBarActivity {
    ImageView imgFavorite;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        }
    public void imageClick(View view){
       imgFavorite =(ImageView)findViewById(R.id.imageView1);
        open();
    }
    public void open(){
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //IMAGE CAPTURE CODE
        startActivityForResult(intent, 0);
    }
     protected void onActivityResult(int requestCode,int resultCode,Intent data){
     super.onActivityResult(requestCode,resultCode,data);
        Bitmap bitmap=(Bitmap)data.getExtras().get("data");
        imgFavorite.setImageBitmap(bitmap);
     }
}

xml 文件:

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="14dp"
    android:layout_marginTop="16dp"
    android:contentDescription="@string/hello_world"
    android:onClick="imageClick"
    android:src="@drawable/camera_launcher" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-03
    • 2017-09-09
    • 1970-01-01
    • 1970-01-01
    • 2013-04-18
    相关资源
    最近更新 更多