This is a follow up to my previous post Crop bitmapdata under mask to create new bitmap. In this example I’ve set-up to allow for the cropped image to be saved out from flash to the server. There is also an additional php script to handle the data being sent from flash to create the exported jpg.
Below is the code that is used to save the cropped image to the server and then load it back into flash.
-
//Save cropped image to the server.
-
function saveCroppedImage(e:Event):void {
-
//Matrix to holder the area to be cropped
-
var maskRect =mcHolder.mcMask.getBounds(mcHolder);
-
//Matrix of image to be cropped
-
var imgMatrix= mcHolder.mcImg.transform.matrix;
-
//Cropped image
-
var myCroppedImage:Bitmap = cropImage(maskRect, imgMatrix, mcHolder.mcMask.width, mcHolder.mcMask.height,mcHolder.mcImg );
-
//Get new matrix of cropped image
-
var m:Matrix = myCroppedImage.transform.matrix;
-
var urlLoader:URLLoader = new URLLoader();
-
//Set jpg quality of the image to be export 1-100
-
var myEncoder:JPGEncoder = new JPGEncoder(80);
-
//Create jpg to be exported
-
var jpgSource:BitmapData = new BitmapData (mcHolder.mcMask.width, mcHolder.mcMask.height);
-
jpgSource.draw(myCroppedImage, m);
-
//Create byte array to hold jpg data
-
var byteArray:ByteArray = myEncoder.encode(jpgSource);
-
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
-
//Send image to the server to be saved
-
var saveJPG:URLRequest = new URLRequest(_path+"saveImage.php?r="+imgID);
-
saveJPG.requestHeaders.push(header);
-
saveJPG.method = URLRequestMethod.POST;
-
saveJPG.data = byteArray;
-
urlLoader.addEventListener(Event.COMPLETE, loadCroppedImage);
-
urlLoader.load(saveJPG);
-
}
Here is an example:
Drag the image around then click “crop image”. The second image that appears has been loaded from the server and clicking on “view in browser” will display the saved image in a new browser window.
Source example:
![]()
Credits: vamapaull, Photo Booth – Flash Webcam Image Capture (insight into export an image from Flash)
Paul Bainbridge




Hi Paul,
How to make this work with loaded external image?
Can you be more specific please.