2010-06-04 39 views

Trả lời

1

Tha thứ cho sự thiếu hiểu biết của tôi, nhưng sự khác biệt này như thế nào so với "bù trừ phơi sáng" được đặt qua setExposureCompensation()? Wikipedia có một số công thức chuyển đổi mà bạn có thể thấy hữu ích.

+0

Tôi không hoàn toàn chắc chắn liệu cài đặt phơi sáng có đạt được kết quả tương tự với cài đặt ISO hay không, có thể thực hiện được. Tuy nhiên mong muốn đang chạy 2.1 và setExposureCompensation có sẵn cho API cấp 8 là 2.2 Vì vậy, phải có một cách khác trong 2.1 để làm điều đó. Cảm ơn câu trả lời của bạn – ee3509

15

bạn nên xem xét các phương pháp flatten(), unflatten(), get(String key), set(String key, String value) trong android.hardware.Camera.Parameters. Đồng thời xem xét source code of that class. Nó có thể làm cho mọi thứ rõ ràng hơn.

Trước tiên, bạn cần có được Camera.Parameters. Unflatten nó vào một String và điều tra nó. Tôi đang phát triển trên HTC Desire cũng một nhận được như sau 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 

Vì vậy, về cơ bản có một phím gọi iso-values để lấy các giá trị được hỗ trợ và một phím iso mà giữ giá trị hiện hành.

Bạn có thể làm như sau:

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); 

Và với tham chiếu đến các thông số flat tôi sẽ giả định rằng có một sự khác biệt giữa các thiết lập bồi thường iso và tiếp xúc.

+0

parameters.get ("iso-values") trả về NULL trên HTC Desire. Bất kỳ ý tưởng nào khác? – radhoo

+0

@radhoo Mong muốn hỗ trợ ISO. Xem câu trả lời của tôi dưới đây để lấy danh sách các giá trị ISO hợp lệ (và từ khóa) từ camera.parameters.flatten(). –

4

câu trả lời đúng là chính xác.

Chỉ

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

lợi nhuận null trên một số thiết bị.

Tuy nhiên bạn có thể đặt iso bởi

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); 

Tôi không biết liệu "800" hoặc "1600" được hỗ trợ trên tất cả các thiết bị

bạn có thể kiểm tra những gì bạn đã làm bởi

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

Để tham khảo, trên hai điện thoại của tôi (cả hai mẫu samsung), giá trị chấp nhận được có tiền tố "ISO" và 800 có sẵn trên một nhưng không phải cả hai trong khi không hỗ trợ 1600. – Jules

8

Hiện tại (KK 4.4.2) android không có API chính thức để quản lý ISO.
Quản lý ISO là một vấn đề phụ thuộc hoàn toàn vào thiết bị và 8/18 thiết bị tôi đã thử nghiệm cho đến nay không hỗ trợ cài đặt ISO.
Điều tra Camera.getParameters().flatten() Chuỗi để kiểm tra các từ khóa hợp lệ, mọi thiết bị đều có thể sử dụng các từ khóa khác nhau !!
Hầu hết các thiết bị sử dụng "iso-giá trị" từ khóa để xác định một dấu phẩy tách ra danh sách-of-thể-giá trị sử dụng với "iso" từ khóa, như thế này:

param.set("iso", valid_value_from_list); 

Một số thiết bị khác sử dụng "iso-mode -giá trị "và" iso "từ khóa (Galaxy Nexus).
Tôi cũng tìm thấy một thiết bị sử dụng "iso-speed-values" và "iso-speed" (Micromax A101).
Một số khác khiến tôi buồn là "nv-picture-iso-values" -> "nv-picture-iso" (LG dual P990).

Làm theo szia câu trả lời về cách sử dụng các từ khóa này.

Dưới đây là một số mã tôi sử dụng để có được một danh sách các giá trị hợp lệ sử dụng từ khoá tiếng:

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

Không nên iso_keyword là "iso-mode" thay vì "iso" cho từ khóa google galaxy nexus? – Thracian

4

kể từ khi tôi có cùng một vấn đề của việc tìm kiếm nếu thiết bị có một tham số ISO Tôi nhìn câu trả lời này https://stackoverflow.com/a/23567103/3976589 và cưa @jc đã giải quyết vấn đề cho 8/18 thiết bị bằng cách liệt kê một số thông số mà anh ta đã tìm thấy trên các thiết bị khác nhau. Dựa trên danh sách đó, tôi thấy rằng mỗi tham số chứa các từ isovalues (đôi khi chỉ có những từ đó, đôi khi có thêm một số từ).

Vì vậy, nếu tôi liệt kê tất cả các tham số của máy ảnh và tìm kiếm một chuỗi chứa cả hai từ, tôi sẽ biết tên của thông số ISO là gì nếu có. Hơn nữa nếu tham số tồn tại, tôi có thể lấy giá trị ISO được hỗ trợ và nếu tôi muốn đặt một trong các giá trị đó tức là thay đổi tham số của máy ảnh, tôi có thể xóa -values ở cuối thông số iso-values và sau đó tôi có thể thay đổi giá trị ISO thành công .

Tôi hiện sẽ chia sẻ mã của mình cho tác vụ này. Đầu tiên một đoạn trích truy xuất danh sách có các giá trị ISO được hỗ trợ.

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; 
    } 

Đoạn mã này chỉ liệt kê các giá trị được hỗ trợ ISO. Trong ứng dụng của tôi, tôi cần chọn ISO thấp nhất. Đây là giải pháp của tôi:

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

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

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

    return minISO; 
} 

Đây là lớp so sánh hai chuỗi và sắp xếp mảng theo thứ tự giảm dần. Tất cả các từ bảng chữ cái đều ở đầu và tất cả các số đều ở cuối. Đây là triển khai của tôi:

// 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; 
} 

} 

Tôi hy vọng câu trả lời của tôi sẽ giúp người khác. :)

Chúc mừng! @ ee3509

Các vấn đề liên quan