3dphotoshoot
view 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 source
1 package com.mutantstargoat.photoshoot3d;
3 import android.app.NativeActivity;
4 import android.util.Log;
5 import static android.opengl.GLES20.*;
6 import android.hardware.Camera;
7 import android.hardware.Camera.CameraInfo;
8 import android.graphics.SurfaceTexture;
10 /*
11 import android.os.Bundle;
12 import android.content.Context;
13 import android.hardware.camera2.*;
14 */
16 public class MainActivity extends NativeActivity {
17 public static String tag = "photoshoot3d";
18 public static boolean frame_pending;
20 public static void foo()
21 {
22 glClearColor(0.2f, 1.0f, 0.3f, 1.0f);
23 }
25 // old camera api (fallback)
26 private static Camera cam;
27 private static SurfaceTexture surftex;
29 public static int start_video(int texid)
30 {
31 int num_cams = Camera.getNumberOfCameras();
32 Log.i(tag, "Found " + num_cams + " cameras");
34 if(num_cams < 1) {
35 return -1;
36 }
38 for(int i=0; i<num_cams; i++) {
39 CameraInfo info = new CameraInfo();
40 Camera.getCameraInfo(i, info);
42 String facing_str = info.facing == CameraInfo.CAMERA_FACING_FRONT ? "front" : "back";
44 Log.i(tag, "camera[" + i + "]: " + facing_str);
45 }
47 surftex = new SurfaceTexture(texid);
48 surftex.setOnFrameAvailableListener(new FrameHandler());
50 cam = Camera.open(0);
52 Camera.Parameters params = cam.getParameters();
53 params.set("orientation", "landscape");
54 cam.setParameters(params);
56 try {
57 cam.setPreviewTexture(surftex);
58 }
59 catch(java.io.IOException e) {
60 Log.e(tag, "failed to set preview texture");
61 cam = null;
62 return -1;
63 }
64 cam.startPreview();
66 return 0;
67 }
69 public static void stop_video()
70 {
71 cam.stopPreview();
72 cam = null;
73 surftex = null;
74 }
76 public static synchronized void update()
77 {
78 if(cam != null && surftex != null && frame_pending) {
79 surftex.updateTexImage();
80 frame_pending = false;
81 }
82 }
83 }
85 class FrameHandler implements SurfaceTexture.OnFrameAvailableListener {
86 @Override
87 public synchronized void onFrameAvailable(SurfaceTexture stex)
88 {
89 MainActivity.frame_pending = true;
90 }
91 }