2010-06-04 57 views
9

有人會知道在哪裏可以從Android SDK中控制相機的ISO設置嗎? 這應該是可能的,因爲HTC Desire上的本機相機應用程序具有ISO設置。Android相機API ISO設置?

回答

1

原諒我的無知,但這與通過setExposureCompensation()設置的「曝光補償」有什麼不同? Wikipedia有一些您可能會覺得有用的轉換公式。

+0

我不完全確定曝光設置是否可以通過iso設置獲得相同的結果,這可能是可能的。 然而,願望正在運行2.1並且setExposureCompensation可用於API級別8,即2.2 因此,在2.1中必須有另一種方式來實現它。 感謝您的回答 – ee3509 2010-06-04 23:20:59

15

你應該看看flatten(),unflatten(),get(String key),set(String key, String value),android.hardware.Camera.Parameters的方法。 另請考慮source code of that class。這可能會讓事情更清楚。

首先您需要獲得Camera.Parameters。將其解開爲String並進行調查。我在HTC Desire的發展,以及一個得到以下String

sharpness-max=30;zoom=0;taking-picture-zoom=0;zoom-supported=true;sharpness-min=0;sharpness=10;contrast=5;whitebalance=auto;jpeg-quality=100;preview-format-values=yuv420sp;jpeg-thumbnail-quality=75;preview-format=yuv420sp;preview-size=640x480;focal-length=3.53;iso=auto;meter-mode=meter-center;front-camera-mode=mirror;flash-mode-values=off,auto,on,torch;preview-frame-rate-values=15;preview-frame-rate=15;focus-mode-values=auto,infinity;jpeg-thumbnail-width=640;jpeg-thumbnail-size-values=640x480,512x384,384x288,0x0;zoom-ratios=100,114,131,151,174,200;saturation-def=5;preview-size-values=1280x720,800x480,768x432,720x480,640x480,576x432,480x320,400x240,384x288,352x288,320x240,272x272,240x240,240x160,176x144,160x120;smart-contrast=off;picture-size-values=2592x1952,2592x1456,2592x1936,2592x1728,2592x1552,2048x1536,2048x1360,2048x1216,2048x1152,1600x1200,1584x1056,1280x960,1280x848,1280x768,1280x720,1024x768,640x480,640x416,640x384,640x368,512x384,400x400,272x272;contrast-min=0;min-exposure-compensation=-4;brightness-min=0;antibanding=auto;taking-picture-zoom-min=0;saturation-min=1;contrast-max=10;vertical-view-angle=42.5;taking-picture-zoom-max=21;contrast-def=5;brightness-max=6;horizontal-view-angle=54.8;brightness=3;jpeg-thumbnail-height=480;cam-mode=0;focus-mode=auto;sharpness-def=10;front-camera-mode-values=mirror,reverse;picture-format-values=jpeg;saturation-max=10;max-exposure-compensation=4;exposure-compensation=0;exposure-compensation-step=0.5;flash-mode=off;effect-values=none,mono,negative,solarize,sepia,posterize,aqua;meter-mode-values=meter-average,meter-center,meter-spot;picture-size=2592x1952;max-zoom=5;effect=none;saturation=5;whitebalance-values=auto,incandescent,fluorescent,daylight,cloudy-daylight;picture-format=jpeg;brightness-def=3;iso-values=auto,deblur,100,200,400,800,1250;enable-caf=off;antibanding-values=off,50hz,60hz,auto 

所以基本上有一個叫iso-values檢索支持的值,並且保持當前價值的關鍵iso關鍵。

你可以做到以下幾點:

Camera cam = Camera.open(); 
Camera.Parameters camParams = cam.getParameters(); 
String supportedIsoValues = camParams.get("iso-values"); //supported values, comma separated String 
camParams.set("iso", (String)newValue); 
cam.setParameters(camParams); 

並參照不平參數我會假設有ISO和曝光補償設置之間的差異。

+0

parameters.get(「iso-values」)在HTC Desire上返回NULL。任何其他想法? – radhoo 2011-10-05 11:22:22

+0

@radhoo慾望應該支持ISO。請參閱下面的答案以從camera.parameters.flatten()中檢索有效的ISO值(以及關鍵字)列表。 – 2014-05-09 14:38:56

4

szias答案是正確的。

只有

String supportedIsoValues = camParams.get("iso-values"); 

回報在某些設備上無效。

不過您可以通過

Camera cam = Camera.open(); 
Camera.Parameters camParams = cam.getParameters(); 
camParams.set("iso", "400"); // values can be "auto", "100", "200", "400", "800", "1600" 
cam.setParameters(camParams); 

設置ISO我不知道是不是「800」或「1600」支持所有設備

你可以檢查你沒有通過

String newVAlue = camParams.get("iso"); 
什麼
+0

作爲參考,在我的兩部手機(均爲三星型號)上,可接受的值以「ISO」爲前綴,800可用於其中一個,但不能同時支持1600. – Jules 2014-02-28 15:19:45

8

現在(KK 4.4.2)android沒有管理ISO的官方API。
ISO管理是一個完全依賴於設備的問題,目前爲止我測試的8/18設備根本不支持ISO設置。
調查Camera.getParameters().flatten()字符串檢查有效的關鍵字,每個設備可以使用不同的關鍵字!
大多數設備使用「異值」關鍵字來定義以逗號分隔的列表的-可能值用「異」,以使用關鍵字,像這樣:

param.set("iso", valid_value_from_list); 

其他一些設備使用「異模式值「和」iso「關鍵字(Galaxy Nexus)。
我還發現使用「等速值」和「等速」(Micromax A101)的設備。
另一個令我傷心的是「nv-picture-iso-values」 - >「nv-picture-iso」(LG雙P990)。

關注szia回答如何使用這些關鍵字。

下面是一些代碼,我用用已知的關鍵字,以得到有效的值的列表:

String flat = param.flatten(); 
String[] isoValues = null; 
String values_keyword=null; 
String iso_keyword=null; 
if(flat.contains("iso-values")) { 
    // most used keywords 
    values_keyword="iso-values"; 
    iso_keyword="iso"; 
} else if(flat.contains("iso-mode-values")) { 
    // google galaxy nexus keywords 
    values_keyword="iso-mode-values"; 
    iso_keyword="iso"; 
} else if(flat.contains("iso-speed-values")) { 
    // micromax a101 keywords 
    values_keyword="iso-speed-values"; 
    iso_keyword="iso-speed"; 
} else if(flat.contains("nv-picture-iso-values")) { 
    // LG dual p990 keywords 
    values_keyword="nv-picture-iso-values"; 
    iso_keyword="nv-picture-iso"; 
} 
// add other eventual keywords here... 
if(iso_keyword!=null) { 
    // flatten contains the iso key!! 
    String iso = flat.substring(flat.indexOf(values_keyword)); 
    iso = iso.substring(iso.indexOf("=")+1); 

    if(iso.contains(";")) iso = iso.substring(0, iso.indexOf(";")); 

    isoValues = iso.split(","); 

} else { 
    // iso not supported in a known way 
} 
+0

不應將iso_keyword設置爲「iso-mode」谷歌星系nexus關鍵字的「iso」? – Thracian 2017-06-21 06:39:09

4

因爲我已經發現的同樣的問題,如果設備有一個ISO參數我看着這個答案https://stackoverflow.com/a/23567103/3976589和鋸@jc通過列出他在不同設備上找到的一些參數,解決了8/18設備的問題。根據該清單,我發現每個參數都包含isovalues這兩個字(有時只是這些字,有時候還有一些額外的)。

因此,如果我列出所有相機參數並搜索包含兩個詞的字符串,我會知道ISO參數的名稱(如果存在)。此外,如果參數存在,我可以採用支持的ISO值,如果我想設置其中一個值,即更改相機參數,我可以在iso-values參數末尾刪除-values,然後我可以成功更改ISO值。

我現在將分享我的代碼以完成此任務。首先檢索一個支持ISO值的列表片段。

private String ISOValuesParameter = null; 
    private String ISOParameter = null; 
    private String ISOValues = null; 


    private void initCamera() { 
     Camera mCamera = Camera.open(); 

     // this will list supported values 
     String ISOvalues = getISOValues(); 
     textViewISO = (TextView) findViewById(R.id.viewISO); 
     textViewISO.setText(ISOvalues); 

    // setting Minimum ISO value 
    if(ISOValuesParameter != null) { 
     Camera.Parameters params = mCamera.getParameters(); 

     ISOParameter = ISOValuesParameter.replace("-values", ""); 
     params.set(ISOParameter, getMinISO()); 

     mCamera.setParameters(params); 

     // get the updated ISO value 
     params = mCamera.getParameters(); 

     String ISO = params.get(ISOParameter); 

     Toast.makeText(this,"ISO set to: " + ISO, Toast.LENGTH_SHORT).show(); 
    } 

    } 

    // returns a list with supported ISO values 
    private String getISOValues() { 
      ISOValuesParamter = getISOValuesParameter(); 
      Camera.Parameters params = mCamera.getParameters(); 
      ISOValues = params.get(ISOValuesParamter); 

      return ISOValues!=null ? ISOValues : "ISO not supported"; 
    } 

    // this will return the name of the ISO parameter containing supported ISO values 
    private String getISOValuesParameter() { 
      Camera.Parameters params = mCamera.getParameters(); 

      String flatten = params.flatten(); 
      String[] paramsSeparated = flatten.split(";"); 
      for(String cur : paramsSeparated) { 
       if(cur.contains("iso") && cur.contains("values")) { 
        return cur.substring(0,cur.indexOf('=')); 
       } 
      } 

      return null; 
    } 

此代碼段僅列出了支持的ISO值。在我的應用程序中,我需要選擇最低的ISO。這裏是我的解決方案:

private String getMinISO() { 
    if(ISOValues == null) { 
     return null; 
    } 

    String[] ISOarray = ISOValues.split(","); 
    Arrays.sort(ISOarray, myComparator); 

    String minISO = ISOarray[ISOarray.length-1]; 

    return minISO; 
} 

這裏myComparator是比較兩個字符串和降序排序的數組類。所有英文字母都在開頭,所有數字都在最後。這是我的實施:

// Singelton class 
public class MyComparator implements Comparator<String> { 

private static MyComparator myComparator = null; 

private MyComparator() {} 

@Override 
public int compare(String a, String b) { 
    return compareString(a,b); 
} 

public static int compareString(String a, String b) { 
    if (a.length() > b.length()) 
     return -1; 
    if (a.length() == b.length()) { 
     if (a.compareTo(b) > 0) 
      return -1; 
     else if (a.compareTo(b) == 0) 
      return 0; 
    } 

    return 1; 
} 

public static synchronized MyComparator getInstance() { 
    if(myComparator==null) { 
     myComparator = new MyComparator(); 
    } 

    return myComparator; 
} 

} 

我希望我的回答可以幫助其他人。 :)

乾杯! @ ee3509