转载请注明出处:http://blog.csdn.net/ning_gg/article/details/54134918
需要SurfaceView的在这里http://blog.csdn.net/ning_gg/article/details/54090446
使用Textureview的话需要确保使用系统是4.0以后并且在Mainfest中开启调用该Activity的硬件
android:hardwareAccelerated="true"
还是照旧贴上代码 为了简单起见我屏蔽掉了其他功能,精简出了预览版本。
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.TextureView;
import com.imapedia.ykdemo.utils.L;
import java.io.IOException;
import java.util.List;
/**
* Created by ning_gg on 2017/1/6.
*/
public class CameraTextureView extends TextureView implements TextureView.SurfaceTextureListener{
private String TAG=CameraTextureView.class.getSimpleName();
private Context mContext;
private Camera mCamera;
private int screenHeight;//屏幕的高度
private int screenWidth;//屏幕的宽度
/***
* 是否支持自动对焦
*/
private boolean isSupportAutoFocus;
public static Camera.Size pictureSize;
private Ca