PDA

View Full Version : bitmap draw once fully loaded



AcolyTe
October 1st, 2009, 04:34 PM
Im trying to draw a bitmap of an dynamically loaded image via xml, and ofcourse i'd like to apply smoothing to my images, as my page resizes with the browser and creates a mess.

The images are loaded with a timer event, which fires every 200ms, and each time this occurs, I'd like to quickly draw the bitmapdata of the image so i can apply the smoothing.

My problem that im having is that the images aren't completely loaded when I run the draw method and so im left with a white box instead.

Currently im using:


function itemHandler(event:Event):void
{
loadThumbs(event);
thumbLoader.unload();
thumbLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE, drawItem);
}

var bmc:MovieClip = new MovieClip();
function drawItem(evt:Event):void
{
bmc = new MovieClip();
var bmd:BitmapData = new BitmapData(170, 150);
bmd.draw(thumbLoader);
var bmp:Bitmap = new Bitmap(bmd);
bmc.addChild(bmp);
bmp.smoothing = true;

placeHolder.addChild(bmc);
}

Any help/advice would be much appreciated, thanks.

Aurelien
October 2nd, 2009, 03:03 AM
Maybe I misunderstood your objective, but why not displaying the Loader directly ? You could still access the smoothing property of any Bitmap content ( loader.content.smoothing ).

AcolyTe
October 2nd, 2009, 07:42 AM
Well, im not quite sure what you mean to be honest.

At the moment, ive resorted to slowing down the timer, and having the successfull bitmaps placed on top the original image, so if someone has a slow connection, they will get a mix of smooth and unsmooth images.

And so, your saying theres a better way to go about this matter?

Scythe
October 2nd, 2009, 11:22 PM
This is what I'm getting. So you're calling the draw method every 200 ms, and you're also calling the draw method after the loading completes which is what's shown in that code. But the image isn't done loading after 200 ms, so it calls the draw method before it completes, and you don't want it to. Why can't you just check to see if thumbloader.content == null? And I definitely don't understand why you're calling unload() right before adding that event listener.