Skip to main content
Participant
May 26, 2012
Question

How to change BitmapData with Native Extension?

  • May 26, 2012
  • 2 replies
  • 1814 views

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.

This topic has been closed for replies.

2 replies

Participant
June 1, 2012

use this function to tell flash that the bitmapData has changed

FREResult FREInvalidateBitmapDataRect(

        FREObject object,

        uint32_t x,

        uint32_t y,

        uint32_t width,

        uint32_t height

);

http://help.adobe.com/en_US/air/extensions/WS460ee381960520ad-866f9c112aa6e1ad46-7ff3.html

User Unknow
Legend
May 27, 2012

Why you send back by pixel? Better send at once whole Bitmapdata

Participant
June 1, 2012

Hi, thanks for reply!

I don't want send anything back, I want just modify bitmapdata pixels in memory (I readed on adobe site that it can be done, but there's no examples).

Thanks