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

81
LINES

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

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

Libraryless. Click here for Pure Java version (585L/5K/17K).

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

Author comment

Began life as a copy of #1000447

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1000448
Snippet name: Android: Open camera v2 (developing)
Eternal ID of this version: #1000448/4
Text MD5: d2686cd856e49a36e9e44efa494cef1f
Transpilation MD5: 3007b8542ae9b45a749c93927c61cd68
Author: stefan
Category: javax android
Type: JavaX source code (Android)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-02-19 12:20:59
Source code size: 2294 bytes / 81 lines
Pitched / IR pitched: No / No
Views / Downloads: 616 / 530
Version history: 3 change(s)
Referenced in: [show references]