我希望相机预览左右反转,
我搜索谷歌,回答是使用Matrix
这是正确的答案吗?
首先,我的来源。
MainActivity.class
private Agen agen = null;
protected static Activity mainActivity = null;
@Override
protected void onCreate(final Bundle savedInstanceState) {
agen = new Agen();
agen.CameraSetting();
}
public static Activity getMainActivity() {
return mainActivity;
}
Agen.class
private CamLiveView camLiveView;
private final FrameLayout liveFrame;
private final Context context;
public Agen() {
Activity activity = MainActivity.getMainActivity();
context = activity;
liveFrame = (FrameLayout) activity.findViewById(R.id.liveview);
public boolean CameraSetting() {
boolean state = false;
try {
LiveCam livecam = CamManage.getInstance();
camLiveView = new CamLiveView(context, livecam, this);
if (liveFrame != null)
liveFrame.addView(camLiveView);
state = true;
} catch (Exception e) {
e.printStackTrace();
} return state;
}
CamManage.class
private static Camera mCamera = null;
public static LiveCam getInstance() {
if (mCamera == null) {
int cameras = Camera.getNumberOfCameras();
mCamera = Camera.open(0);
if (mCamera != null) {
mCamera.lock();
}
} else {
}
return getLiveCam();
}
getLiveCam
static private LiveCam getLiveCam() {
LiveCam livecam = new LiveCam() ;
Camera.Parameters params = mCamera.getParameters();
liveCam.preSize = params.getPreviewSize();
liveCam.preFormat = params.getPreviewFormat();
liveCam.camera = mCamera;
return liveCam;
}
LiveCam.class
public class LiveCam {
public Camera camera;
public Camera.Size preSize;
public int preFormat;
}
这是我的来源。
但我不知道在哪里使用matrix
。
请给我建议
感谢。
添加
public class CamLiveView extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder mHolder;
private Camer mCamera;
private int preWidth;
private int preHeight;
private int preFormat;
private boolean playing = false;
public CamLiveView(Context context, LiveCam livecam) {
super(context);
mHolder = getHolder();
mHolder.addCallback(this);
mCamera = livecam.camera;
preWidth = livecam.preSize.width;
preHeight = livecam.preSize.height;
preFormat = livecam.previewFormat;
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
cameraPlay();
}
public boolean cameraPlay() {
if (mHolder == null)
return false;
try {
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview();
playing = true;
} catch (Exception e) {
return false;
} return true;
}