-
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.
- Inspired & assisted by:
- This extension implicitly includes
extensionkit
which must be available in a folder beside this one.
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]
<include path="/path/to/extensionkit" />
<include path="/path/to/camera" />
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));
}
}