An OpenFL Android extension to use Camera.
- Done with OpenFL 4.9.2.
- reference tutorial
- Sending Data back from Native Code to Haxe
- The JNI short code reference
For the basics of an Android extension, have a look at RayToast
Available Methods
initCamera()Void
: just a teststartCamera():Void
: fires up camera and takes picturecaptureImageAs(imgName:String):Void
: Mostly needed this one. It takes the image name as a parameter and saves it
- Two steps
- Call it like
AnCam.captureImageAs("myPhoto");
- Listen to the event as
AnCam.dispatcher.addEventListener(AnCam.CAM_CAPTURED_EVENT,onCamCaptured);
- Complete Example implementation is here
- Sample code for implementation is as below
// add the event listener
AnCam.dispatcher.addEventListener(AnCam.CAM_CAPTURED_EVENT,onCamCaptured);
// capture the image and save it
AnCam.captureImageAs("myPhoto");// it will be saved as myPhoto.jpg
// load it in the application
private function onCamCaptured(e:Event):Void{
var sCamImage:String = System.userDirectory + 'myPhoto' +'.jpg';
var r:URLRequest = new URLRequest(sCamImage);
var loaderImage:Loader = new Loader();
loaderImage.load(r);
addchild(loaderImage);
}
- The JNI short code reference
- change
build.gradle
located atdependencies/android/build.gradle
to haveclasspath 'com.android.tools.build:gradle:::ANDROID_GRADLE_PLUGIN::'
- it looks as
dependencies { classpath 'com.android.tools.build:gradle:::ANDROID_GRADLE_PLUGIN::' }