回答
在这里拍摄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="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);
}
}
}
我想用前置摄像头 – mohan
检查此拍照http://stackoverflow.com/questions/2779002/how-to-open-front-camera-on-android-platform – Pratik
你能否把你的“案例0:”改为“case CAMERA_PIC_REQUEST:” – alicanbatur
或学习从机器人here的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);
}
}
activity_choosing_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"/>
- 1. ImageView未显示拍摄的照片android
- 2. 拍摄照片,并显示在ImageView的
- 3. iPhone标题摄像头,imageview不显示拍摄的照片
- 4. Android摄像头 - 防止拍摄画面的照片
- 5. Android - ImageView不会显示用相机拍摄的照片
- 6. 在imageView中显示上次拍摄的照片? (相机)
- 7. 在android中的相机拍摄的imageview照片中显示图片
- 8. 如何在Android中使用ImageView拍摄照片后显示拍摄的图片并避免同步问题
- 9. 拍摄画面的照片与VB.NET
- 10. 的Android相机拍摄多张照片
- 11. 使用ViewBinder,SimpleCursorAdapter,SQLite在ListView上显示摄像机拍摄的照片
- 12. 从相机拍摄照片
- 13. 无法显示拍摄的照片
- 14. 避免画廊保存在Android的相机拍摄的照片
- 15. Android Studio应用程序ImageView在拍摄照片时不显示图像
- 16. Android的后置摄像头拍摄照片,而不预览
- 17. 如何在Flex中拍摄摄像头快照图片?
- 18. 在表格视图中显示从相机拍摄的照片
- 19. 拍摄一张照片,然后将其显示到ImageView
- 20. 如何创建拍摄照片的功能拍摄+保存
- 21. 如何显示在Android中使用相机拍摄的图像
- 22. IntentFilter相机和拍摄的照片
- 23. 拍摄来自相机的照片
- 24. 何时拍摄照片?
- 25. 我可以通过Android模拟器相机拍摄我的桌面照片吗?
- 26. 将拍摄的照片从ImageView存储到手机存储器
- 27. Android前置摄像头拍摄倒影照片
- 28. 如何发送通过电子邮件从相机拍摄的照片Android
- 29. Jquery摄像头插件当照片拍摄时没有显示图片
- 30. 如何检测照片是否由前置摄像头拍摄
同样的问题回答这里: http://stackoverflow.com/questions/5991319/capture-image-from-camera-and-display-in-activity – user650309