Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SurfaceHolderCallback implements SurfaceHolder.Callback {
- private static final int IMAGE_WIDTH = 512;
- private static final int IMAGE_HEIGHT = 384;
- private static final String ORIENTATION = "orientation";
- private static final String ROTATION = "rotation";
- private static final String PORTRAIT = "portrait";
- private static final String LANDSCAPE = "landscape";
- public void surfaceCreated(SurfaceHolder holder) {
- camera = Camera.open();
- //Surface.setOrientation(Display.DEFAULT_DISPLAY,Surface.ROTATION_90);
- Parameters p = camera.getParameters();
- p.setPictureSize(IMAGE_WIDTH, IMAGE_HEIGHT);
- p.set(ORIENTATION, PORTRAIT);
- p.set(ROTATION, 90);
- // p.setPreviewSize(640, 480);
- Camera.Size s = p.getSupportedPreviewSizes().get(0);
- Log.d(APP, "preview params " + s.width +"/"+ s.height);
- p.setPreviewSize( s.width,s.height );
- p.setPictureFormat(PixelFormat.JPEG);
- p.set("flash-mode", "auto");
- camera.setParameters(p);
- try {
- camera.setPreviewDisplay(surfaceHolder);
- } catch (Throwable ignored) {
- Log.e(APP, "set preview error.", ignored);
- }
- }
- public void surfaceChanged(SurfaceHolder holder, int format, int width,
- int height) {
- if (isPreviewRunning) {
- camera.stopPreview();
- }
- try {
- camera.startPreview();
- } catch(Exception e) {
- Log.d(APP, "Cannot start preview", e);
- }
- isPreviewRunning = true;
- }
- ...
Advertisement
Add Comment
Please, Sign In to add comment