Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How can I load bitmapdata from an array?

New Here ,
Jul 31, 2009 Jul 31, 2009

I am working on a prototype of a system that will take stills from an attached video camera, store them in an array, then pull them back from the array and animate them.

Thus far I've been able to create new bitmaps, put them in an array, and draw them to the stage.

I have the video source coming to the stage and I have been able to take stills.

The combined system, however, goes through the array, draws the bitmaps to the stage but they are not the sequence of stills. Instead, it is a set of bitmap objects that change every time I click the mouse to take a new still. My guess is that whatever I am doing wrong has caused the bitmapdata to remain dynamically linked to the video source or to be changed every time a new still has been taken.

Any pointers would be appreciated. I feel like I am close but missing something major in how AS3 works.

// libraries to display bitmap of video
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.DisplayObject;

// get and show the input from the camera
var cam:Camera = Camera.getCamera();
var vid:Video = new Video();
vid.attachCamera(cam);
this.addChild(vid);
var imageArray:Array = new Array();

// take and display picture
stage.addEventListener(MouseEvent.CLICK, takephoto);

var screenS:BitmapData = new BitmapData(cam.width, cam.height);
var screenS_image:Bitmap=new Bitmap(screenS);

function takephoto(e:MouseEvent):
    void {

    screenS.draw(vid) ;
    imageArray.push(screenS);

    }

stage.addEventListener(KeyboardEvent.KEY_DOWN, showArray);   
   
function showArray(e:KeyboardEvent):
    void {
        for (var i:int = 0; i < imageArray.length; i++) {
   
        trace(imageArray);
       
        var bm1:Bitmap = new Bitmap(imageArray);
        this.addChild(bm1);
        bm1.x = 0 + (i*100) ;
        bm1.y = 240 ;

        }
   
    }

TOPICS
ActionScript
497
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 31, 2009 Jul 31, 2009

The problem is that every time you call draw() on your BitmapData instance, it replaces what was drawn to that instance previously.  So when you later try to attach the BitmapData to a Bitmap, you'll only see whatever was last drawn to that BitmapData.

I would create a new Bitmap instance for every frame you need to draw, and then store the Bitmaps into the array and just add those to the displaylist later.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 31, 2009 Jul 31, 2009
LATEST

That is it exactly, thanks.

"zompo" on Flashkit.com suggested the following code, which is what you're suggesting, and works:

function takephoto(e:MouseEvent):
        void {
        var bd:BitmapData = new BitmapData(screenS.rect.width, screenS.rect.height);
        bd.draw(vid) ;
        imageArray.push(bd);

       }

I'm putting it here incase it's helpful to anyone else.

-atrowbri

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines