如何访问摄像机的Andr​​oid手机? [英] How do I access the camera on Android phones?

查看:149
本文介绍了如何访问摄像机的Andr​​oid手机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Java编写的程序,它在图像文件和操纵的形象。现在,我试图访问摄像头,这样我可以拍摄照片,并给它的图像处理程序,但是我迷路了,如何做到这一点。我读过关于相机类,以及如何要求授权的信息,但我不知道如何实际拍摄照片。如果任何人有我应该在哪里开始,或者如果他们知道一个很好的教程中我真的AP preciate任何提示。谢谢!

I've written a program in Java that takes in an image file and manipulates the image. Now I'm trying to access the camera so that I can take the photo and give it to the image processing program however I'm lost as to how to do this. I've read the information about the camera class and how to ask for permissions but I don't know how to actually take the photo. If anyone has any tips on where I should begin or if they know of a good tutorial I'd really appreciate it. Thanks!

推荐答案

谷歌是你最好的朋友,这里有一些教程:

Google is your best friend, here are some tutorials:

<一个href="http://p2p.wrox.com/book-professional-android-application-development-isbn-978-0-470-34471-2/72528-article-using-android-camera.html">Using相机

如何-编程的谷歌Android摄像头拍照

拍照的相机模拟器

相机

首先编辑AndroidManifest.xml中,添加摄像头权限:

First edit your AndroidManifest.xml, add the camera permission:

<uses-permission android:name="android.permission.CAMERA"/>

摄像机服务已被打开和关闭:

Camera service has to be opened and closed:

Camera camera = Camera.open();
 //Do things with the camera
camera.release();

您可以设置相机设置,例如:

You can set camera settings, e.g.:

Camera.Parameters parameters = camera.getParameters();
parameters.setPictureFormat(PixelFormat.JPEG); 
camera.setParameters(parameters);

要拍张照片:

private void takePicture() {
  camera.takePicture(shutterCallback, rawCallback, jpegCallback); 
}

ShutterCallback shutterCallback = new ShutterCallback() {
  public void onShutter() {
    // TODO Do something when the shutter closes.
  }
};

PictureCallback rawCallback = new PictureCallback() {
  public void onPictureTaken(byte[] _data, Camera _camera) {
    // TODO Do something with the image RAW data.
  }
};

PictureCallback jpegCallback = new PictureCallback() {
  public void onPictureTaken(byte[] _data, Camera _camera) {
    // TODO Do something with the image JPEG data.
  }
};

不要忘了相机的布局添加到您的主布局的XML。

Do not forget to add the camera layout to your main layout xml.

这篇关于如何访问摄像机的Andr​​oid手机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆