Back to project page FloatCamera.
The source code is released under:
Apache License
If you think the Android project FloatCamera listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.kenai.camera; //w ww . j av a 2 s . c om import com.kenai.function.message.XLog; import android.content.Context; import android.graphics.ImageFormat; import android.hardware.Camera; import android.view.SurfaceHolder; import android.view.SurfaceView; public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private final String TAG = "CameraPreview"; private final SurfaceHolder myHolder; private final Camera myCamera; public CameraPreview(Context context, Camera camera) { super(context); myCamera = camera; myHolder = getHolder(); myHolder.addCallback(this); // necessary before android3.0 myHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { XLog.xLog(TAG, "surfaceChanged"); /* * ???????????????????? ????????????????? */ if (myHolder.getSurface() == null) { // ??surface???? return; } /* * ??????????????????? ??????????? ???????????myHolder? */ try { myCamera.setPreviewDisplay(myHolder);// ??holder??????????? myCamera.startPreview();// ??????????????????????????? } catch (Exception e) { XLog.xLog(TAG, "Error setting camera preview:\n" + e.getMessage()); e.printStackTrace(); } } public void surfaceCreated(SurfaceHolder holder) { XLog.xLog(TAG, "surfaceCreated"); // surface???????????????????????? try { Camera.Parameters parameters = myCamera.getParameters(); // ?????????? parameters.setPreviewSize(720, 480); parameters.setPreviewFormat(ImageFormat.NV21); parameters.setFocusMode(Camera.Parameters.SCENE_MODE_AUTO); parameters.setPictureFormat(ImageFormat.JPEG); parameters.setJpegQuality(80); // ???????? parameters.setPictureSize(parameters.getPictureSize().width, parameters.getPictureSize().height); // parameters.setRotation(270); // android2.3.3???????? myCamera.setParameters(parameters); } catch (Exception e) { } try { myCamera.setPreviewDisplay(holder); myCamera.startPreview(); } catch (Exception e) { XLog.xLog(TAG, "Error setting camera preview:\n" + e.getMessage()); e.printStackTrace(); } } public void surfaceDestroyed(SurfaceHolder holder) { XLog.xLog(TAG, "surfaceDestroyed"); } }