Skip to content
Access to the camera for taking & retrieving stills in iOS + Android
Objective-C++ Haxe C++ Other
Branch: 0.2-master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
camera
dependencies/android
project
.gitattributes
.gitignore
CHANGELOG.md
LICENSE.md
README.md
build-ios.sh
build.bat
haxelib.json
include.xml

README.md

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));
    }
}
You can’t perform that action at this time.