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

87
LINES

< > BotCompany Repo | #1015069 // Android Take Picture, old transpilation

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

Libraryless. Click here for Pure Java version (87L/1K/4K).

import java.security.NoSuchAlgorithmException;
import java.security.MessageDigest;
import java.lang.reflect.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.util.regex.*;
import java.util.*;

import android.app.Activity;
import android.widget.*;
import android.graphics.*;
import android.hardware.Camera;
import android.view.*;

public class main {
  static Activity androidContext;
  
  public static void main(String[] args) throws Exception {
    System.out.println("Listing cameras...");
    
    androidContext.runOnUiThread(new Runnable() {
public void run() { try {

      int n = Camera.getNumberOfCameras();
      System.out.println("Cameras: " + n);
  
      final Camera cam = Camera.open(0/*n-1*/);
      
      Camera.Parameters p = cam.getParameters();
      p.setPreviewSize(100, 100);
      cam.setParameters(p);

      SurfaceView surfaceView = new SurfaceView(androidContext);
      SurfaceHolder surfaceHolder = surfaceView.getHolder();
      surfaceHolder.addCallback(new CamCallback());
      surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
      
      androidContext.setContentView(surfaceView);
      
      cam.setPreviewDisplay(surfaceHolder);
      cam.startPreview();
      
      System.out.println("Preview started.");
      
      /*surfaceView.post(new Runnable() {
public void run() { try {

        cam.takePicture(null, null, null, new JpegCallback());
      
} catch (Exception __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}});
      
      System.out.println("Waiting for callback");*/
    
} catch (Exception __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}});
  }
  
  static class CamCallback implements SurfaceHolder.Callback {
    public void surfaceChanged (SurfaceHolder holder, int format, int width, int height) {
      System.out.println("surfaceChanged");
    }
    public void surfaceCreated (SurfaceHolder holder) {
      System.out.println("surfaceCreated");
    }
    public void surfaceDestroyed (SurfaceHolder holder) {
      System.out.println("surfaceDestroyed");
    }
  }
  
  static class ShutterCallback implements Camera.ShutterCallback {
    public void onShutter() {
      System.out.println("Shutter!");
    }
  }
  
  static class JpegCallback implements Camera.PictureCallback {
    public void onPictureTaken (byte[] data, Camera cam) {
      TextView tv = new TextView(androidContext);
      tv.setText("Picture data: " + data.length);
      androidContext.setContentView(tv);
      
      System.out.println("Picture data: " + data.length);
      cam.release();
      System.out.println("Camera released.");
    }
  } 
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1015069
Snippet name: Android Take Picture, old transpilation
Eternal ID of this version: #1015069/1
Text MD5: e94c1b1ee898f06b3b8ea14ed204c192
Transpilation MD5: e94c1b1ee898f06b3b8ea14ed204c192
Author: stefan
Category: javax android
Type: JavaX source code (Android)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-07 18:23:45
Source code size: 2824 bytes / 87 lines
Pitched / IR pitched: No / No
Views / Downloads: 252 / 322
Referenced in: [show references]