如何在imageview中显示android中照相机拍摄的照片
有人能告诉我们如何在安卓系统中使用前置摄像头拍摄的imageview照片中显示图片吗有人能提供代码吗如何在imageview中显示android中照相机拍摄的照片,android,Android,有人能告诉我们如何在安卓系统中使用前置摄像头拍摄的imageview照片中显示图片吗有人能提供代码吗 谢谢这是代码,请尝试 这是我的xml文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="
谢谢这是代码,请尝试 这是我的xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/linear">
<Button android:id="@+id/btn" android:layout_width="200dp"
android:layout_height="wrap_content" android:text="Click" />
<ImageView android:id="@+id/img_preview"
android:layout_width="fill_parent" android:layout_height="fill_parent" />
</LinearLayout>
这是onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode){
case CAMERA_PIC_REQUEST:
if(resultCode==RESULT_OK){
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
imgView.setImageBitmap(thumbnail);
}
}
}
或者学习android的API演示,试试这个
public class TakingImage extends AppCompatActivity {
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;
public void onCreate(Bundle savedInstance){
super.onCreate(savedInstance);
setContentView(R.layout.activity_choosing_photo);
button = (Button)findViewById(R.id.button_select);
imageView = (ImageView)findViewById(R.id.image_view);
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
活动\u选择\u photo.xml
<ImageView
android:id="@+id/image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/flower"
android:layout_marginLeft="100dp"/>
<Button
android:id="@+id/button_select"
android:layout_below="@+id/image_view"
android:layout_marginTop="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select"
android:layout_marginLeft="140dp"/>
这里回答了相同的问题:我想使用前置摄像头拍照检查您是否可以将“案例0:”更改为“案例摄像头图片请求”:
<ImageView
android:id="@+id/image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/flower"
android:layout_marginLeft="100dp"/>
<Button
android:id="@+id/button_select"
android:layout_below="@+id/image_view"
android:layout_marginTop="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select"
android:layout_marginLeft="140dp"/>