开发者

Resize Image before Uplaod In flash AS3 using AJAX

开发者 https://www.devze.com 2023-04-06 01:33 出处:网络
I want make a image up-loader in flash.i will call to Ajax to upload image, AJAX check for flash re si开发者_如何学Czer and it re size image using flash re sizer and upload on sever.please any body ca

I want make a image up-loader in flash.i will call to Ajax to upload image, AJAX check for flash re si开发者_如何学Czer and it re size image using flash re sizer and upload on sever.please any body can help me how i can re size image in flash before upload on server.


For what its worth, You don't need AJAX as a middle layer. Flash can handle the entire operation itself. You can upload images as a Multipart form. There is a great class for this here: http://code.google.com/p/in-spirit/source/browse/trunk/projects/MultipartURLLoader/ru/inspirit/net/MultipartURLLoader.as

As for resizing an image, the simplest way is to attach the image to a sprite, and then use bitmapData.draw(theSprite). 1. Add bitmap to sprite. 2. Scale Sprite to size. 3. Create empty bitmapdata to the scaled size of the sprite. 4. Call bitmapdata.draw(theSprite). 5. Encode the bitmapdata to jpeg or png using AS3CoreLib http://code.google.com/p/as3corelib/ 6. Upload the jpeg to the server using the mlutiplartULRloader above.

private function uploadImage():void
        {
            var encoder:JPGEncoder = new JPGEncoder(80);
            var thumbnailImage:ByteArray = encoder.encode(smallBitmapData);
            // Use MultipartURLLoader to pass the message string and image data.
            mpLoader = new MultipartURLLoader();
            mpLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
            mpLoader.addFile(thumbnailImage, "filename.jpg", "badge_thumb");
            mpLoader.addEventListener(Event.COMPLETE, onUserAddedOrUpdated);
            mpLoader.load("Your PHP file URL that processes the form");
        }
0

精彩评论

暂无评论...
验证码 换一张
取 消