SurfaceView正在交换红色和蓝色Google Glass相机的颜色

gka*_*ann 1 camera android google-glass google-gdk

出于某些奇怪的原因,surfaceView正在显示图像,但红色和蓝色通道被交换.我使用的代码与Github项目中的代码基本相同,但有一些小的改动.

我正在使用它的代码是:

public class CameraView extends SurfaceView implements SurfaceHolder.Callback{

private SurfaceHolder surfaceHolder = null;
private Camera camera = null;

public CameraView(Context context) {
    super(context);
    surfaceHolder = this.getHolder();
    surfaceHolder.addCallback(this);
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    camera = Camera.open();
    Parameters parameters = camera.getParameters();
    parameters.setPreviewFpsRange(30000, 30000);            
    camera.setParameters(parameters);   
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    if (camera != null){                    // Start the preview for surfaceChanged
        try {
            camera.setPreviewDisplay(holder);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            this.releaseCamera();
        }
        camera.startPreview();
    }
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    this.releaseCamera();                   // Do not hold the camera during surfaceDestroyed - view should be gone...
}

public void releaseCamera() {
    if (camera != null) {
        camera.release();
        camera = null;
    }
}

}
Run Code Online (Sandbox Code Playgroud)

有什么想法为什么这种颜色交换?

小智 6

我遇到了同样的问题,它让我抓狂.经过大量的努力,我发现,由于某些奇怪的原因,当布局只包含FrameLayout时,会发生这种情况,而FrameLayout只包含相机的SurfaceView而没有其他布局元素.在我的情况下,我在FrameLayout上添加了空TextView并解析了它.奇怪但工作.(最终我用这个TextView来显示文本,所以这就是样式和位置属性的原因)

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="${relativePackage}.${activityClass}"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/CameraView" />

 <TextView
    android:id="@+id/status_text"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="5dip"
    android:layout_gravity="center_horizontal|top"

    android:padding="5dip"
    android:textColor="#000000"

    android:text="" />
Run Code Online (Sandbox Code Playgroud)