For the Android Flash Mobile App, I am trying to capture a preview frame from a camera.
Unfortunately, I cannot use the built-in AIR camera class because the camera does not focus unless I call setMode () (which is unacceptable because it freezes the user interface).
So, I decided to write an Extension Extension for this. The extension itself works (I get the correct image data in NativeCamera.pixels), but I cannot pass Frame using FREBitmapData. On the ActionScript side, BitmapData has the correct dimension, but it remains black.
My java code
package com.jumptomorrow.nativecamera;
import java.nio.ByteBuffer;
import com.adobe.fre.FREBitmapData;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;
public class NativeCameraGrabFrameFunction implements FREFunction {
@Override
public FREObject call(FREContext context, FREObject[] object) {
try {
FREBitmapData out = null;
try {
out = FREBitmapData.newBitmapData(NativeCamera.size.width, NativeCamera.size.height, false, new Byte[]{0xf,0xf,0x0,0x0});
out.acquire();
ByteBuffer bb = out.getBits();
bb = ByteBuffer.wrap(NativeCamera.pixels);
out.invalidateRect(0, 0, NativeCamera.size.width, NativeCamera.size.height);
} catch (Exception e) {
e.printStackTrace();
}
try {
out.release();
} catch(Exception e) {
e.printStackTrace();
}
return out;
} catch (IllegalStateException e) {
e.printStackTrace();
}
return null;
}
}
My ActionScript Code
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.utils.ByteArray;
import net.hires.debug.Stats;
public class camera_test extends Sprite
{
private var nc:NativeCameraInterface;
private var bitmap:Bitmap;
public function camera_test()
{
super();
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
nc = new NativeCameraInterface();
try {
nc.startCamera();
}
catch(e:Error) {
trace(e.getStackTrace());
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
protected function onEnterFrame(event:Event):void
{
if(nc) {
var bmpd:BitmapData = nc.getFrame() as BitmapData;
try {
var bmp:Bitmap = new Bitmap(bmpd);
addChild(bmp);
bmp.scaleX = bmp.scaleY = 2;
} catch(e:Error) {
trace("failed");
}
}
}
}
}
Does anyone know what this could be?
source
share