2012-08-23 24 views
5

Tôi đang mã hóa cho máy tính bảng Android và tôi muốn ứng dụng của mình sử dụng chế độ xem dọc của chế độ xem trước máy ảnh surfaceView. Đó là cảnh quan theo mặc định và tôi đã thử mã sau để xoay sang chế độ xem dọc:cách thay đổi máy ảnh Android thành chân dung trong surfaceview?

public void surfaceCreated(SurfaceHolder holder){ 
    // The Surface has been created, acquire the camera and tell it where to draw. 
    mCamera = Camera.open(); 
    Parameters params = mCamera.getParameters(); 
    // If we aren't landscape (the default), tell the camera we want portrait mode 
    if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE){ 
    params.set("orientation", "portrait"); // "landscape" 
    // And Rotate the final picture if possible 
    // This works on 2.0 and higher only 
    //params.setRotation(90); 
    // Use reflection to see if it exists and to call it so you can support older versions 
     try { 
     Method rotateSet = Camera.Parameters.class.getMethod("setRotation", new Class[] { Integer.TYPE }); 
     Object arguments[] = new Object[] { new Integer(270) }; 
     rotateSet.invoke(params, arguments); 
     } catch (NoSuchMethodException nsme) { 
     // Older Device 
     Log.v("CameraView","No Set Rotation"); 
     } catch (IllegalArgumentException e) { 
     Log.v("CameraView","Exception IllegalArgument"); 
     } catch (IllegalAccessException e) { 
     Log.v("CameraView","Illegal Access Exception"); 
     } catch (InvocationTargetException e) { 
     Log.v("CameraView","Invocation Target Exception"); 
     } 
    } 
    mCamera.setParameters(params); 
    try{ 
    mCamera.setPreviewDisplay(holder); 
    } catch (IOException exception) { 
    mCamera.release(); 
    mCamera = null; 
    } 
} 

Nhưng nó không hoạt động. Ai có thể sửa nó không?

+0

cũng đã thử với đối số Đối tượng [] = new Object [] {new Integer (90)}; nhưng tôi vẫn không thể sửa nó. –

+0

Kể từ khi bạn nhận được surfaceview để làm việc, bạn có thể cung cấp cho tôi một ví dụ. Tôi cần truyền từ ipcamera sang android của mình và tôi muốn sử dụng surfaceview – Lily

Trả lời

7

Bạn có thể sẽ muốn sử dụng setDisplayOrientation chức năng như sau:

public void surfaceCreated(SurfaceHolder holder) { 
    if (Build.VERSION.SDK_INT >= 8) mCamera.setDisplayOrientation(90); 
} 

Sử dụng các công cụ máy ảnh params.set("orientation"... là không đồng nhất giữa các thiết bị và thực sự là pre-SDK ngôn ngữ 8.

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