Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Resizing images

Syferius
Level 2
Level 2
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.
0 Replies
aponnusa
Employee
Employee
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
Syferius
Level 2
Level 2
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.
aponnusa
Employee
Employee
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...))