“自动对焦” “相机”功能我的 Android 应用程序的模块

发布于 2024-12-06 10:44:59 字数 159 浏览 1 评论 0原文

几天以来,我一直在为我的应用程序使用 CAMERA 模块。 我定制了完整的相机模块,而不是通过意图调用硬件内置的移动相机。我使用了快门、图片等回调 现在我正在尝试为这款定制相机添加变焦和自动对焦功能。任何人都可以让我知道添加缩放和自动对焦功能的方法以及清单文件中应提及的所需权限。希望我能尽快得到帮助。

I have been working with the CAMERA module for my application since few days.
I have customized the complete camera module instead of invoking the hardware inbuilt mobile camera through an intent. I have used the call backs for shutter, picture etc
Now I am trying to add the ZOOM and AUTO-FOCUS features to this customized camera. Can anybody please let me know the way to add the ZOOM and AUTO-FOCUS features along with the required permissions which should be mentioned in the manifest file..hope i will be helped as soon as possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忘羡 2024-12-13 10:44:59

我的一些观察结果。

1) Camera.autoFocus 是一次性调用,适用于
Camera.getParameters.getFocusMode()FOCUS-MODE-AUTO
FOCUS-MODE-MACRO,其他情况下不需要调用
autoFocus 方法。请参阅 API 文档并认真遵循它们。

2) 一次性调用,表示该方法不注册
AutoFocusCallback 实例连续接收通知。

3) 相反,FOCUS-MODE-AUTO 甚至不是动态连续对焦
持续的。相反,您可能想使用 FOCUS-MODE-EDOF
FOCUS-MODE-CONTINUOUS-PICTURES 取决于 API 级别和
您正在使用和构建的 SDK 版本。

4) 有每一个
实际设备相机可能不支持某些功能的可能性
FOCUS-MODE 常量,例如 EDOFINFINITE。始终确保
当您创建相机参数时,您会检查
getSupportedFocusModes 并使用适用的常量。

5) 呼叫
camera.autoFocus 就在 camera.takePicture 之前,会使
PictureCallBack 中生成的 jpeg-byte-array 至少为 50%
超过其原始尺寸。不显式调用 autoFocus() 可能会
有时会导致之前的 autoFocus() 以非常快的速度结束
低分辨率可能会导致 jpeg 字节数组长度仅为
10K 字节,导致 BitmapFactory 中的图像位图为空。

6) 关于自动对焦权限,请参阅 API 文档。

7)关于
变焦,并不像实现自动对焦那么复杂
特征。取决于屏幕交互,例如滑块或硬件
诸如音量键之类的键,您可以实现一个 ZoomChangeListener
您可以在 Camera 实例注册后立即向 Camera 注册
open(intcameraId)接收。

Couple of observations from my end.

1) Camera.autoFocus is a one-time call, applicable when
Camera.getParameters.getFocusMode() is either FOCUS-MODE-AUTO or
FOCUS-MODE-MACRO, in other cases you don't need to invoke the
autoFocus method. See the API Docs and follow them devotedly.

2) By one-time call, it means that this method does not register the
AutoFocusCallback instance to receive notifications continuously.

3) Rather, FOCUS-MODE-AUTO isn't even a dynamic and continuous focus
constant. Instead, you might want to use FOCUS-MODE-EDOF or
FOCUS-MODE-CONTINUOUS-PICTURES depending on the API Level and the
SDK version that you are using and building for.

4) There is every
possibility that the actual Device Camera may not support some
FOCUS-MODE constants, such as EDOF or INFINITE. Always make sure
when you are creating the camera-parameters, you check for
getSupportedFocusModes and use the applicable constants.

5) Calling
camera.autoFocus just before camera.takePicture can bloat the
resulting jpeg-byte-array in the PictureCallBack to at least 50%
more than it's original size. Not calling autoFocus() explicitly may
sometimes cause the previous autoFocus() to end at a very
low-resolution that may result a jpeg-byte-array length of only a
10K bytes, resulting in a null image bitmap from the BitmapFactory.

6) Regarding auto-focus permissions, see the API Docs.

7) Regarding
Zoom, it is not as complicated as implementing the Auto-focus
feature. Depending on screen-interaction such as slider, or hardware
keys such as volume-keys, you could implement a ZoomChangeListener
that you can register with the Camera as soon as the Camera instance
is received from open(int cameraId).

開玄 2024-12-13 10:44:59

对于缩放 (2x):

   Camera.Parameters parameters = camera.getParameters();
   parameters.set("zoom", "2.0");
   parameters.set("taking-picture-zoom", "20");

对于 api 级别 > 5 使用 api,例如 setZoom()

用于自动对焦(取自 zxing)

public final boolean onKeyDown(int keyCode, KeyEvent event) {

synchronized(this) {
if (!bIsPictureTaking) {

    if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_CAMERA)    {

            if (!bIsPictureTaking && !bIsAutoFocusStarted){

                YourAutoFocusCallback autoFocusCallBack = new YourAutoFocusCallback();

                camera.autoFocus(autoFocusCallBack);

final class YourAutoFocusCallback implements Camera.AutoFocusCallback {


  private static final long AUTOFOCUS_INTERVAL_MS = 1500L;

  private final CameraConfigurationManager configManager;
  private boolean reinitCamera;
  private Handler autoFocusHandler;
  private int autoFocusMessage;

  AutoFocusCallback(CameraConfigurationManager configManager) {
    this.configManager = configManager;
  }

  void setHandler(Handler autoFocusHandler, int autoFocusMessage) {
    this.autoFocusHandler = autoFocusHandler;
    this.autoFocusMessage = autoFocusMessage;
  }

  public void onAutoFocus(boolean success, Camera camera) {
    if (autoFocusHandler != null) {
      Message message = autoFocusHandler.obtainMessage(autoFocusMessage, success);
      autoFocusHandler.sendMessageDelayed(message, AUTOFOCUS_INTERVAL_MS);
      autoFocusHandler = null;

        configManager.setDesiredCameraParameters(camera);
    } else {
     }
  }

}

For zoom (2x):

   Camera.Parameters parameters = camera.getParameters();
   parameters.set("zoom", "2.0");
   parameters.set("taking-picture-zoom", "20");

For api level > 5 use the api's like setZoom() etc

For autofocussing (taken from zxing)

public final boolean onKeyDown(int keyCode, KeyEvent event) {

synchronized(this) {
if (!bIsPictureTaking) {

    if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_CAMERA)    {

            if (!bIsPictureTaking && !bIsAutoFocusStarted){

                YourAutoFocusCallback autoFocusCallBack = new YourAutoFocusCallback();

                camera.autoFocus(autoFocusCallBack);

.

final class YourAutoFocusCallback implements Camera.AutoFocusCallback {


  private static final long AUTOFOCUS_INTERVAL_MS = 1500L;

  private final CameraConfigurationManager configManager;
  private boolean reinitCamera;
  private Handler autoFocusHandler;
  private int autoFocusMessage;

  AutoFocusCallback(CameraConfigurationManager configManager) {
    this.configManager = configManager;
  }

  void setHandler(Handler autoFocusHandler, int autoFocusMessage) {
    this.autoFocusHandler = autoFocusHandler;
    this.autoFocusMessage = autoFocusMessage;
  }

  public void onAutoFocus(boolean success, Camera camera) {
    if (autoFocusHandler != null) {
      Message message = autoFocusHandler.obtainMessage(autoFocusMessage, success);
      autoFocusHandler.sendMessageDelayed(message, AUTOFOCUS_INTERVAL_MS);
      autoFocusHandler = null;

        configManager.setDesiredCameraParameters(camera);
    } else {
     }
  }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文