Guest User

Untitled

a guest
Jul 9th, 2010
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. class SurfaceHolderCallback implements SurfaceHolder.Callback {
  2.     private static final int IMAGE_WIDTH = 512;
  3.     private static final int IMAGE_HEIGHT = 384;
  4.     private static final String ORIENTATION = "orientation";
  5.     private static final String ROTATION = "rotation";
  6.     private static final String PORTRAIT = "portrait";
  7.     private static final String LANDSCAPE = "landscape";
  8.  
  9.     public void surfaceCreated(SurfaceHolder holder) {
  10.         camera = Camera.open();
  11.  
  12.         //Surface.setOrientation(Display.DEFAULT_DISPLAY,Surface.ROTATION_90);            
  13.         Parameters p = camera.getParameters();
  14.         p.setPictureSize(IMAGE_WIDTH, IMAGE_HEIGHT);
  15.         p.set(ORIENTATION, PORTRAIT);
  16.         p.set(ROTATION, 90);
  17.         // p.setPreviewSize(640, 480);
  18.  
  19.         Camera.Size s = p.getSupportedPreviewSizes().get(0);
  20.         Log.d(APP, "preview params " + s.width +"/"+ s.height);            
  21.         p.setPreviewSize( s.width,s.height );
  22.  
  23.         p.setPictureFormat(PixelFormat.JPEG);
  24.         p.set("flash-mode", "auto");
  25.         camera.setParameters(p);
  26.  
  27.         try {
  28.             camera.setPreviewDisplay(surfaceHolder);
  29.         } catch (Throwable ignored) {
  30.             Log.e(APP, "set preview error.", ignored);
  31.         }
  32.     }
  33.  
  34.     public void surfaceChanged(SurfaceHolder holder, int format, int width,
  35.                                int height) {
  36.  
  37.         if (isPreviewRunning) {
  38.             camera.stopPreview();
  39.         }
  40.         try {
  41.             camera.startPreview();
  42.         } catch(Exception e) {
  43.             Log.d(APP, "Cannot start preview", e);    
  44.         }
  45.         isPreviewRunning = true;
  46.     }
  47.  
  48.     ...
Advertisement
Add Comment
Please, Sign In to add comment