How to change BitmapData with Native Extension?
Hi,
how can i modify bitmapdata with ANE without copy/clone?
I want to send bitmapdata to native extension (iOS), then changes bitmapdata pixels, then I want to see changed Bitmap (which uses this bitmapdata) on stage.
My code:
ActionScript
bd = new BitmapData(300,300,true,0x00000000); //create bitmapdata
bd.fillRect(bd.rect,0xff0000FF);
var btm:Bitmap; //create bitmap
btm = new Bitmap(bd);
addChild(btm);
myExtension = new MyExtension(); //create extension instance
myExtension.ChangeBitmapData(bd);
//bitmap stay same ![]()
iOS
FREObject ChangeBitmapData(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
// Obtain access to the bitmap data pixels ..
FREBitmapData bmd;
FREAcquireBitmapData(argv[0], &bmd);
// We'll now loop over each pixel write them into the AS3 bitmapData memory
int x, y;
// There may be extra pixels in each row due to the value of
// bmd.lineStride32, we'll skip over those as needed
int offset = bmd.lineStride32 - bmd.width;
uint32_t *bmdPixels = bmd.bits32;
for(y=0; y<bmd.height; y++) {
for(x=0; x<bmd.width; x++, bmdPixels ++) {
// Values are currently in RGBA8888, so each colour
// value is currently a separate number
int red = x % 2 == 0 ? 0 : 255;
int green = 0;
int blue = 0;
int alpha = 255;
// Combine values into ARGB32
* bmdPixels = (alpha << 24) | (red << 16) | (green << 8) | blue;
}
bmdPixels += offset;
}
FREReleaseBitmapData(argv[0]);
return nil;
}
Where's error? How to change pixels correctly? Please help.
