玻璃摄像头preVIEW显示为乱码 [英] Glass camera preview display is garbled

查看:233
本文介绍了玻璃摄像头preVIEW显示为乱码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让现场摄像机preVIEW在谷歌玻璃来显示。

I am trying to get a live camera preview to display in Google Glass.

我使用所有的摄像头默认值(和也尝试过使用几个不同的图像格式;理想情况下,我可以使用的YUV格式之一),但显示在显示屏上的图像是乱码,这样的

I'm using all of the camera defaults (and have also tried using a few different image formats; ideally, I can use one of the YUV formats), but the image that shows up in the display is garbled, like this:

的布局很简单:

<?xml version="1.0" encoding="utf-8"?>
<TextureView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scan_preview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

下面是活动code:

public class ScanActivity extends Activity {
    private static final String kTag = ScanActivity.class.getSimpleName();
    private TextureView mVideoCaptureView = null;
    private Camera mCamera = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scan);
        setTitle(R.string.title_scan);

        mVideoCaptureView = (TextureView) findViewById(R.id.scan_preview);
        mVideoCaptureView.setKeepScreenOn(true);
        mVideoCaptureView.setSurfaceTextureListener(new VideoCaptureTextureListener());
    }

    @Override
    protected void onPause() {
        super.onPause();
        stopVideo();
    }

    @Override
    protected void onResume() {
        super.onResume();
        startVideo();
    }

    private void startVideo() {
        if (mCamera != null) {
            mCamera.release();
        }
        mCamera = Camera.open();
        if (null != mVideoCaptureView) {
            try {
                mCamera.setPreviewTexture(mVideoCaptureView.getSurfaceTexture());
            } catch (IOException e) {
                Log.e(kTag, "Error setting preview texture", e);
                return;
            }
        }
        mCamera.startPreview();
    }

    private void stopVideo() {
        if (null == mCamera)
            return;
        try {
            mCamera.stopPreview();
            mCamera.setPreviewDisplay(null);
            mCamera.setPreviewTexture(null);
            mCamera.release();
        } catch (IOException e) {
            Log.w(kTag, e);
        }
        mCamera = null;
    }

    private final class VideoCaptureTextureListener implements TextureView.SurfaceTextureListener {

        @Override
        public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
            stopVideo();
            return true;
        }

        @Override
        public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
            startVideo();
        }

        @Override
        public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
        }

        @Override
        public void onSurfaceTextureUpdated(SurfaceTexture surface) {
        }
    }
}

你有什么想法,为什么这完全未经处理的相机preVIEW显示不正确?

Do you have any idea why this completely unmanipulated camera preview is not displaying correctly?

推荐答案

这已经在这里找到答案: http://stackoverflow.com /一/九十五万○四百二十七分之一千九百二十五万七千○七十八

This has been answered here: http://stackoverflow.com/a/19257078/950427

长期:

Camera.Parameters params = camera.getParameters();
params.setPreviewFpsRange(30000, 30000);
camera.setParameters(params);

Shorterm(测试):

有关的快速测试和使用的,只需添加到您的最外层的看法:

For quick testing and usage, simply add to your outermost view:

android:layout_margin="1dp"

例如:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_margin="1dp"
    android:layout_height="match_parent" >

    <org.opencv.android.JavaCameraView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/tutorial2_activity_surface_view" />

</LinearLayout>

这篇关于玻璃摄像头preVIEW显示为乱码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆