Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

86
LINES

< > BotCompany Repo | #1000447 // Android: Open camera v2 (developing)

JavaX source code (Android) [tags: use-pretranspiled] - run with: the app

Libraryless. Click here for Pure Java version (95L/1K/5K).

1  
!636
2  
!711 // runnable {
3  
4  
import android.app.Activity;
5  
import android.widget.*;
6  
import android.graphics.*;
7  
import android.hardware.Camera;
8  
import android.view.*;
9  
10  
main {
11  
  static Activity androidContext;
12  
  
13  
  psvm {
14  
    print "Listing cameras..."
15  
    
16  
    androidContext.runOnUiThread(runnable {
17  
      int n = Camera.getNumberOfCameras();
18  
      System.out.println("Cameras: " + n);
19  
  
20  
      //final Camera cam = Camera.open(0/*n-1*/);
21  
      
22  
      TextureView mTextureView = new TextureView(androidContext);
23  
      
24  
      mTextureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
25  
        Camera mCamera;
26  
        
27  
        public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
28  
            mCamera = Camera.open(0);
29  
  
30  
            try {
31  
                mCamera.setPreviewTexture(surface);
32  
                mCamera.startPreview();
33  
            } catch (IOException ioe) {
34  
                // Something bad happened
35  
            }
36  
        }
37  
  
38  
        public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
39  
            // Ignored, Camera does all the work for us
40  
        }
41  
  
42  
        public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
43  
            mCamera.stopPreview();
44  
            mCamera.release();
45  
            return true;
46  
        }
47  
  
48  
        public void onSurfaceTextureUpdated(SurfaceTexture surface) {
49  
            // Invoked every time there's a new Camera preview frame
50  
        }        
51  
      });
52  
      
53  
      androidContext.setContentView(mTextureView);
54  
    });
55  
  }
56  
  
57  
  static class CamCallback implements SurfaceHolder.Callback {
58  
    public void surfaceChanged (SurfaceHolder holder, int format, int width, int height) {
59  
      print "surfaceChanged"
60  
    }
61  
    public void surfaceCreated (SurfaceHolder holder) {
62  
      print "surfaceCreated"
63  
    }
64  
    public void surfaceDestroyed (SurfaceHolder holder) {
65  
      print "surfaceDestroyed"
66  
    }
67  
  }
68  
  
69  
  static class ShutterCallback implements Camera.ShutterCallback {
70  
    public void onShutter() {
71  
      print "Shutter!"
72  
    }
73  
  }
74  
  
75  
  static class JpegCallback implements Camera.PictureCallback {
76  
    public void onPictureTaken (byte[] data, Camera cam) {
77  
      TextView tv = new TextView(androidContext);
78  
      tv.setText("Picture data: " + data.length);
79  
      androidContext.setContentView(tv);
80  
      
81  
      System.out.println("Picture data: " + data.length);
82  
      cam.release();
83  
      print "Camera released."
84  
    }
85  
  } 
86  
}

Author comment

Began life as a copy of #1000431

From example: http://developer.android.com/reference/android/view/TextureView.html

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, hxnwyiuffukg, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1000447
Snippet name: Android: Open camera v2 (developing)
Eternal ID of this version: #1000447/1
Text MD5: 43254d024c1fea58cdb39cb7b13d5e3f
Transpilation MD5: 2748d48c90dd85041bddcdb41a10657c
Author: stefan
Category: javax android
Type: JavaX source code (Android)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-08-07 15:29:40
Source code size: 2568 bytes / 86 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 606 / 597
Referenced in: [show references]