by pass as3 8191px problem

Core Concept : Dun draw in bitmap

Example:
in urUploader, Thumbnail can over 8191px, loadBytes is according to file size, so if file size too large, yr machine will hang.

[as3]private function genThumbnail():void {
var l:Loader = new Loader();
l.loadBytes(transcodeManager.baAlchemy);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, onThumbnailComplete);
}

private function onThumbnailComplete(e:Event):void {
var b:Bitmap = MCUtil.scaledImage(Bitmap(e.target.content).bitmapData, new ThumbnailLayout().width);
_thumbnail.addChild(b);

var data:Object = { uploadJob : this };
dispatchEvent(new UploadJobEvent(UploadJobEvent.THUMBNAIL_GENERATED, data));
}

[/as3]
This is the scale function, so after scale to small size, now can draw 🙂

[as3]public static function scaledImage(bd:BitmapData, s:Number = 120) : Bitmap
{
var newWidth:Number;
var newHeight:Number;
var result:BitmapData;
var bitmap:BitmapData = bd;
var size:Number = s;
var matrix:Matrix = new Matrix();
try
{
if (bitmap.width > bitmap.height)
{
newWidth = size;
newHeight = bitmap.height * (size / bitmap.width);
}
else
{
newHeight = size;
newWidth = bitmap.width * (size / bitmap.height);
}
matrix.scale(newWidth / bitmap.width, newHeight / bitmap.height);
result = new BitmapData(newWidth, newHeight);
result.draw(bitmap, matrix);
bitmap.dispose();
return new Bitmap(result);
}
catch (e:Error)
{
trace("Scaled image error");
}
return null;
}// end function[/as3]

ref: photobox photobook program

Posted in: AS3