如何访问摄像机的Andr​​oid手机?摄像机、手机、Andr、oid

2023-09-06 00:19:02 作者:梦绕魂牵

我用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:

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.