views:

164

answers:

2

Been trying to smooth images loaded with FileReferece with no luck. Below is the code I'm using:

fileRef = new FileReference();
fileRef.addEventListener(Event.COMPLETE, fileLoaded);

private function fileLoaded(e:Event):void{
    var ldr:Loader = new Loader();             
    ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void{
        var bm:Bitmap = Bitmap(e.target.content as Bitmap);
        bm.smoothing = true;
        img.load(bm)
    }); 
    ldr.loadBytes(fileRef.data);
}   

<custom:SWFLoaderAdvanced id="img"/>

bm.smoothing should've smoothened the loaded image, but for some reason it doesn't. Am I missing something here?

Note: SWFLoaderAdvanced automatically smoothens any image that's loaded inside it. It works perfectly with loaded images other than the ones loaded with FileReference.

A: 

I'm not sure why bm.smoothing isn't working, perhaps it is but the effect is barely noticeable. One thing you could try is a BlurFilter.

import flash.filters.BlurFilter;
var blur:BlurFilter = new BlurFilter(1, 1, 5);

Where the first and second arguments are blurX and blurY, and the third is the quality. I imagine you can apply this to a Bitmap object, probably using this function:

bitmapDataObject.applyFilter();

That function is detailed further in the AS3 Reference; I'm not at a computer with Flash installed so I can't test exactly how this would work. You will definitely be able to apply blur effects to Bitmap objects though, and if you do a very slight one with high quality, it'll appear to smooth the image. Check out BlurFilter and BitmapData in the docs.

Hope this helps!

debu
Thanks for the workaround. I'm pretty sure that smoothing isn't happening - it is very noticeable. Still looking for a solution.
Yeti
+1  A: 

I believe that the data is loaded into flash as byteArray, try this and see what happens.

your line here:

var bm:Bitmap = Bitmap(e.target.content as Bitmap);

wants to be:

var bm:Bitmap = new Bitmap(e.target.content as BitmapData);
shortstick
Tried this and it throws a ReferenceError: Error #1069: Property data not found on flash.display.LoaderInfo and there is no default value.
Yeti
you are correct, that was my mistake and getting mixed up with Loader classes. it should have read 'e.target.content' as listed in your example. edited to fix.
shortstick