PDA

View Full Version : can't save and display Bitmaps



maloola
July 27th, 2008, 05:46 AM
i'm using Flex 2, as3.
i have a webcam class, that shows a webcam stream and after snapping, creates a Bitmap from the webcam stream and adds the Bitmap to a display object. the user can snap again.
i'm trying to add a "prev" "next" option. i'm saving the snapped images (Bitmaps) in an Array, so i can display the Bitmaps after paging:

var data:BitmapData = _imgSnapped.bitmapData;
var bitmap:Bitmap = new Bitmap(data);
_snapArr[indx] = bitmap;

and displaying the Bitmaps like so:
var data:BitmapData = _lastSnapped.bitmapData;
var bitmap:Bitmap = new Bitmap(data);
_prevImgSnapped = bitmap;
_previewDisplay.addChild(_prevImgSnapped);

the problem is, the Bitmaps seem to empty. i know the Bitmap i save in the array is the same one (it has the same reference), but the variables of the bitmapData are gone!!!! (for example, tracing the bitmapData.width leads to a EOFError).

how can i properly save my Bitmaps with all their bitmapData? :puzzled:

wvxvw
July 27th, 2008, 11:59 AM
Read about lock()/unlock() (http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html#unlock()) methods of BitmapData class.
Bitmap may update the bitmapData inside itself it it's unlocked and will not update if it's locked. Anyhoo, I'd use BitmapData.clone() method to make sure I'm saving an unbound copy of BitmapData and nothing else that may destroy it isn't referencing it.

maloola
July 28th, 2008, 07:18 AM
thank you :D
i tried the clone() method and my Bitmaps are saved properly now!