A cross platform API for low level camera access
Switch branches/tags
Nothing to show
Clone or download
Latest commit 7219ae4 Mar 29, 2018


Camera Kit Codename One

Camera Kit is a cross platform API for low level camera access. It's based on https://github.com/CameraKit/camerakit-android/[Camera Kit Android] and uses it for the Android version of this API. In iOS the implementation is based directly on the native OS API's.

Important not all API's are implemented in a cross platform way at this time as this cn1lib is highly experimental. Basic things might not work...


The code in this repository is under the MIT license which effectively allows you to do with it as you please. We'd still be happy to get good pull requests.

Basic Usage

CameraKit ck = CameraKit.create();

// will happen in unsupported platforms such as the simulator!
if(ck != null) {
  Form hi = new Form("Native Camera", new LayeredLayout());
  ck.addCameraListener(new CameraListener() {
      public void onError(CameraEvent ev) {
          // handle camera errors

      public void onImage(CameraEvent ev) {
          // Callback when a photo is captured
          byte[] jpegData = ev.getJpeg();

      public void onVideo(CameraEvent ev) {
          // Callback when a photo is captured
          String videoFile = ev.getFile();
  Button video = new Button();
  FontImage.setMaterialIcon(video, FontImage.MATERIAL_VIDEOCAM);
  video.addActionListener(e -> {
      Boolean b = (Boolean)video.getClientProperty("capturing");
      if(b == null) {
          video.putClientProperty("capturing", Boolean.TRUE);
          FontImage.setMaterialIcon(video, FontImage.MATERIAL_VIDEOCAM_OFF);
      } else {
          video.putClientProperty("capturing", null);
          FontImage.setMaterialIcon(video, FontImage.MATERIAL_VIDEOCAM);
  FloatingActionButton fab = FloatingActionButton.createFAB(FontImage.MATERIAL_CAMERA);
  fab.bindFabToContainer(hi, CENTER, BOTTOM);
  fab.addActionListener(e -> ck.captureImage());

  Button toggleCamera = new Button();
  FontImage.setMaterialIcon(toggleCamera, FontImage.MATERIAL_CAMERA_FRONT);
  Button toggleFlash = new Button();
  FontImage.setMaterialIcon(toggleFlash, FontImage.MATERIAL_FLASH_ON);
  toggleCamera.addActionListener(e -> ck.toggleFacing());
  toggleFlash.addActionListener(e -> ck.toggleFlash());
  Container buttons = BoxLayout.encloseY(video, toggleCamera, toggleFlash);

You can see the full demo project here.


If used in the first form of the application it is recommended that you have a splash screen at least for the first time the application loads. This is essential for iOS where screenshots are generated for the splash screens.