3dphotoshoot
diff src/android/MainActivity.java @ 8:9fc7d52f578d
FINALLY I'm getting an image out of the camera
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 25 May 2015 04:14:38 +0300 |
parents | 7f6e6eb3d20e |
children | d1b456d08713 |
line diff
1.1 --- a/src/android/MainActivity.java Sat May 23 23:14:44 2015 +0300 1.2 +++ b/src/android/MainActivity.java Mon May 25 04:14:38 2015 +0300 1.3 @@ -15,6 +15,7 @@ 1.4 1.5 public class MainActivity extends NativeActivity { 1.6 public static String tag = "photoshoot3d"; 1.7 + public static boolean frame_pending; 1.8 1.9 public static void foo() 1.10 { 1.11 @@ -30,6 +31,10 @@ 1.12 int num_cams = Camera.getNumberOfCameras(); 1.13 Log.i(tag, "Found " + num_cams + " cameras"); 1.14 1.15 + if(num_cams < 1) { 1.16 + return -1; 1.17 + } 1.18 + 1.19 for(int i=0; i<num_cams; i++) { 1.20 CameraInfo info = new CameraInfo(); 1.21 Camera.getCameraInfo(i, info); 1.22 @@ -42,7 +47,12 @@ 1.23 surftex = new SurfaceTexture(texid); 1.24 surftex.setOnFrameAvailableListener(new FrameHandler()); 1.25 1.26 - cam = Camera.open(); 1.27 + cam = Camera.open(0); 1.28 + 1.29 + Camera.Parameters params = cam.getParameters(); 1.30 + params.set("orientation", "landscape"); 1.31 + cam.setParameters(params); 1.32 + 1.33 try { 1.34 cam.setPreviewTexture(surftex); 1.35 } 1.36 @@ -63,10 +73,11 @@ 1.37 surftex = null; 1.38 } 1.39 1.40 - public static void update() 1.41 + public static synchronized void update() 1.42 { 1.43 - if(cam != null && surftex != null) { 1.44 + if(cam != null && surftex != null && frame_pending) { 1.45 surftex.updateTexImage(); 1.46 + frame_pending = false; 1.47 } 1.48 } 1.49 } 1.50 @@ -75,7 +86,6 @@ 1.51 @Override 1.52 public synchronized void onFrameAvailable(SurfaceTexture stex) 1.53 { 1.54 - Log.i(MainActivity.tag, "new video frame"); 1.55 - stex.updateTexImage(); 1.56 + MainActivity.frame_pending = true; 1.57 } 1.58 }