任何人都可以告诉如何在androidview中使用前置摄像头拍摄的照片中显示图片任何人都可以提供代码
谢谢
解决方法:
这是代码试试吧
这是我的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>
这是活动代码
Button btn;
int CAMERA_PIC_REQUEST = 0;
ImageView imgView;
imgView = (ImageView) findViewById(R.id.img_preview);
btn = (Button) findViewById(R.id.btn);
btn.setCompoundDrawables(null, getResources().getDrawable(R.drawable.icon), null, null);
btn.setonClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent camera_intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(camera_intent, CAMERA_PIC_REQUEST);
}
});
这是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);
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。