Skip to content

Access to the camera for taking & retrieving stills in iOS + Android

License

Notifications You must be signed in to change notification settings

UAVImagProcessing/camera

 
 

Repository files navigation

Camera

Take photos from a mobile device's camera and receive the byte data

  • Triggers the built-in camera in iOS and Android, or the Photo Library picker in the iOS Simulator.

  • Returns the captured photo to Haxe as JPEG byte data via a CameraEvent on the stage.

  • Simulates a camera event from provided BitmapData for non-mobile platforms.

  • Allows placing a BitmapData overlay over the built-in camera display.

    • TODO: Implement overlay in Android.

Acknowledgements

Dependencies

  • This extension implicitly includes extensionkit which must be available in a folder beside this one.

Installation

git clone https://github.com/bazzisoft-openfl-extensions/extensionkit
git clone https://github.com/bazzisoft-openfl-extensions/camera
lime rebuild extensionkit [linux|windows|mac|android|ios]
lime rebuild camera [linux|windows|mac|android|ios]

Usage

project.xml

<include path="/path/to/extensionkit" />
<include path="/path/to/camera" />

Haxe

class Main extends Sprite
{
    public function new()
    {
        super();

        Camera.Initialize();

        stage.addEventListener(CameraEvent.PHOTO_CAPTURED, HandlePhotoCaptured);
        stage.addEventListener(CameraEvent.PHOTO_CANCELLED, function(e) { trace(e); });

        #if !mobile
        // When testing on flash/desktop, CapturePhoto() should send this image...
        Camera.SetFakePhotoResult(Assets.getBitmapData("assets/mySimulatedPhoto.jpg"));
        #end

        // Show this PNG over the top of the native camera view
        Camera.SetCameraOverlayImage(Assets.getBitmapData("assets/img/camera-overlay.png"));
        
        // Take photo, limit max possible size to 1024x1024, JPEG quality 0.9
        Camera.CapturePhoto(1024, 0.9);

        ...
    }

    public function HandlePhotoCaptured(e:CameraEvent) : Void
    {
        var bitmapData:BitmapData = e.GetBitmapData();
        var jpegBytes:Bytes = e.GetImageData();

        addChild(new Bitmap(bitmapData));
    }
}

About

Access to the camera for taking & retrieving stills in iOS + Android

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C++ 47.7%
  • Haxe 43.1%
  • C++ 8.0%
  • Other 1.2%