简体   繁体   English

Android相机和SurfaceView无法正常工作

[英]Android camera and SurfaceView not working

I'm getting this weird error in my code 我的代码中出现这个奇怪的错误 一种

Cannot resolve symbol 'surfaceCallback' 无法解析符号“ surfaceCallback”

theese are my current imports 这些是我目前的进口

import android.content.Intent;
import android.hardware.Camera;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

实现SurfaceHolder.Callback您的活动,并通过thisaddCallBack();

SurfaceHolder.Callback is related to its Surface. SurfaceHolder.Callback与其表面有关。

Abstract interface to someone holding a display surface. 对拿着显示表面的某人的抽象接口。 Allows you to control the surface size and format, edit the pixels in the surface, and monitor changes to the surface. 允许您控制曲面的大小和格式,编辑曲面中的像素以及监视曲面的变化。 This interface is typically available through the SurfaceView class. 通常可通过SurfaceView类使用此接口。

When using this interface from a thread other than the one running its SurfaceView , you will want to carefully read the methods lockCanvas() and Callback.surfaceCreated() . 从运行SurfaceView的线程以外的线程使用此接口时,您将需要仔细阅读方法lockCanvas()Callback.surfaceCreated()

You need to implement the SurfaceCallback interface of SurfaceView as below: 您需要实现SurfaceViewSurfaceCallback接口,如下所示:

public class callbackSurfaceMethod implements SurfaceHolder.Callback{
  @Override
public void surfaceCreated(SurfaceHolder holder) {
    // TODO Auto-generated method stub

}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {
    // TODO Auto-generated method stub

}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    // TODO Auto-generated method stub

}

Change in your code. 更改您的代码。

surfaceView = (SurfaceView)findViewById(R.id.surfaceview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(callbackSurfaceMethod );

try this code, 试试这个代码,

surfaceView = (SurfaceView)findViewById(R.id.surfaceview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM