Highlighted

Resizing images

Syferius

17-03-2009

Is there any solution to resize images that users are
uploading ? I was trying to resize it before upload, but i can't
change FileReference's data without resaving resized image and
rebrowsing it. Please advise. Thanks.

Replies

Highlighted

aponnusa

Employee

17-03-2009

You can always access the actual image as bytearray from the
file reference. And then manipulate the bytearray to create a new
resized image.



Ex:

protected function init():void

var actualImage:ByteArray = new ByteArray();

actualImage = _fileReference.data as ByteArray;

var loader:Loader = new Loader();


loader.contentLoaderInfo.addEventListener(Event.COMPLETE,byteImageLoaded);

loader.loadBytes(actualImage);

}



protected function byteImageLoaded(p_event:Event):void

{

//Explore alternative ways to create a Thumbnail

var sourceBMP:Bitmap = p_event.currentTarget.loader.content
as Bitmap;

//ur logic to resize the bitmap

}



Thanks
Highlighted

Syferius

17-03-2009

Yes. This is done for now. But after this manipulations, i
want to return ByteArray to FileReference.data and then
FilePublisher.uploadFileReference(). This is my problem.
Highlighted

aponnusa

Employee

17-03-2009

Use mx.graphics.codec.PNGEncoder or jpeg encoder to encode
the byte array as png or jpg image. Then use the binary publisher {

http://livedocs.adobe.com/labs/acrobatcom/com/adobe/rtc/collaboration/BinaryPublisher.html
} to save it as a file. (binaryPublisher.publish(args...))