简体   繁体   English

Android API 7(2.1 Eclair)下的相机的字符串参数

[英]Camera's string parameters under Android API 7 (2.1 Eclair)

I am developping an application that uses the Camera preview, take picture, and zoom functions. 我正在开发一个使用Camera预览,拍照和缩放功能的应用程序。

I am trying to remain compatible with the Android API level 7 (2.1 Eclair), which does not implement Camera.Parameters.getMaxZoom() , Camera.Parameters.setZoom() , etc, so I have to use the String parameters returned by the hardware. 我试图保持与Android API级别7(2.1埃克莱尔),它没有实现兼容Camera.Parameters.getMaxZoom() Camera.Parameters.setZoom()等,所以我必须使用String被返回的参数硬件。 For example: 例如:

final String zoomSupportedString = parameters.get("zoom-supported"); // parameters is a Camera.Parameters 
final boolean zoomSupported = (zoomSupportedString != null ? Boolean.parseBoolean(zoomSupportedString) : false);

if (zoomSupported) {
    // Computes the min an max zoom levels for taking a picture:
    final int minTake = parameters.getInt("taking-picture-zoom-min");
    final int maxTake = parameters.getInt("taking-picture-zoom-max"); 

    // etc.
}

But not all the devices use the same parameters, and I couldn't find any valid camera parameters list on the internet. 但是,并非所有设备都使用相同的参数,而且我在互联网上找不到任何有效的相机参数列表。

By checking the values returned by Camera.Parameters.flatten() (see doc ) on a HTC I could find "zoom-supported" , "taking-picture-zoom-min" , "taking-picture-zoom-max" and "max-zoom" . 通过检查HTC上Camera.Parameters.flatten()返回的值(请参阅doc ),我可以找到"zoom-supported" "taking-picture-zoom-min""taking-picture-zoom-max" "taking-picture-zoom-min""taking-picture-zoom-max""max-zoom" And surprisingly, I have found no "min-zoom" . 令人惊讶的是,我没有发现"min-zoom"

But the parameter "taking-picture-zoom-min" doesn't exist on Samsung Galaxy S, for example, and this leads null to be returned and getInt() to throw a NumberFormatException: 'null' cannot be parsed as an integer . 但是,例如,参数"taking-picture-zoom-min"在三星Galaxy S上不存在,这导致返回null并导致getInt()引发NumberFormatException: 'null' cannot be parsed as an integer

Knowing that I am trying to remain compatible with Android-7, is there any better way to handle the zoom than using the string values returned by the hardware? 知道我正在尝试与Android-7兼容,是否有比使用硬件返回的字符串值更好的方法来处理缩放? And if so, is it possible to find somewhere a list of all the valid zoom parameters (or even a list by vendor)? 如果是这样,是否有可能在某处找到所有有效缩放参数的列表(甚至是供应商的列表)?

i know it's an old topic, but for those that are searching for Camera zoom... i had the same issue and now that i have 2 android devices which work differently, both had something in commmon. 我知道这是一个古老的话题,但是对于那些正在搜索“相机变焦”的人……我遇到了同样的问题,现在我有2个工作原理不同的android设备,两者都具有某种通用性。

Camera.Parameters.setZoom(int value) didn't work on both of them, so i started testing. Camera.Parameters.setZoom(int value)不适用于它们两个,所以我开始测试。 One device has "taking-picture-zoom-...;" 一台设备具有“拍照变焦……”功能。 but both devices have "zoom=...;" 但两个设备都带有“ zoom = ...;” in the Camera.Parameters. 在Camera.Parameters中。 On the device that has "taking-picture-zoom-...;", if i use Camera.Parameters.set("zoom", int value) it would crash, while on the other it would work just fine. 在具有“ take-picture-zoom -...;”的设备上,如果我使用Camera.Parameters.set("zoom", int value) ,它将崩溃,而在另一方面,它将正常工作。 So, my solution is, when initializing the camera I store a boolean that holds true for Camera.Parameters.get("taking-picture-zoom")!=null , and false otherwise. 因此,我的解决方案是,在初始化相机时,我会存储一个布尔值,该布尔值对Camera.Parameters.get("taking-picture-zoom")!=null ,否则为false。 From that moment on, when setting zoom, just check the boolean and use the appropriate zoom-command... and that's it, works like a charm ! 从那一刻起,设置缩放时,只需检查布尔值并使用适当的缩放命令即可,仅此而已,就像一个魅力! ofcourse, you could also just make a String hold the appropriate command and use that when setting zoom. 当然,您也可以仅使String保留适当的命令,并在设置缩放比例时使用该命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM