Android的 - 摄像头preVIEW [英] Android - Camera Preview

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

问题描述

我想要的相机preVIEW

这是我的code,它不会引发任何错误,但屏幕仍然是黑色的。任何想法?

  this.setContentView(R.layout.camera preVIEW);
SurfaceView cameraSurface =(SurfaceView)findViewById(R.id.cp preVIEW);
SurfaceHolder支架= cameraSurface.getHolder();
holder.addCallback(本);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
this.camera = Camera.open();
this.camera.set previewDisplay(保持器);
this.camera.start preVIEW();
 

相机preview.xml

 < XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT>
    < SurfaceView
        机器人:ID =@ + ID / CP preVIEW
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_gravity =中心>

    < / SurfaceView>
< / LinearLayout中>
 

解决方案

正在太早调用的最后三行。你必须等待表面要调用设置previewDisplay()前ppared $ P $,你必须等待表面的大小( surfaceChanged())之前调用启动preVIEW()该项目有你所需要的。

i'm trying the camera preview

This is my code and it doesn't throw any error, but the screen is still black. Any ideas?

this.setContentView(R.layout.camerapreview);    
SurfaceView cameraSurface = (SurfaceView)findViewById(R.id.cpPreview);
SurfaceHolder holder = cameraSurface.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
this.camera = Camera.open();
this.camera.setPreviewDisplay(holder);
this.camera.startPreview();

camerapreview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    <SurfaceView
        android:id="@+id/cpPreview"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_gravity="center">

    </SurfaceView>
</LinearLayout>

解决方案

You are calling the last three lines too early. You have to wait for the surface to be prepared before calling setPreviewDisplay() and you have to wait for the surface to be sized (surfaceChanged()) before calling startPreview(). This project has what you need.

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

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