What I’ve been upto

I cannot believe how quickly the past 6 months have flown by. Has it really been since January since I last made a blog post. It’s to easy to just tweet rather than post something to the blog. Follow me on Twitter

I would like to say it has been a busy 6 months but that would be lying. This year was the slowest start to the year for me since I started freelancing over 10 years ago. So with all that free time I started to take a serious look at development with AIR for android and Ipad. Still got nothing to show at the moment but things are moving along nicely.

dopeawards-logoThings have also been moving along nicely with dopeawards. Some nice new features have been added to help improve the UI. You can check them out here.

I’ve set-up a new twitter account as I feel it’s time to drop the @glasgow_flasher account. You can now follow me @scotflash. I would like to thank all the peeps(tweeps) that have started following my second account. I’ve also taken a moment to get set up with google+. You can find me here.Follow me on google+ Need an invite? Linky

Posted in Android, Flash AS3, What i am upto | Tagged , , , , , , | Leave a comment

Save masked image to server. AS3

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.

  1. //Save cropped image to the server.
  2. function saveCroppedImage(e:Event):void {
  3.  //Matrix to holder the area to be cropped
  4.  var maskRect =mcHolder.mcMask.getBounds(mcHolder);
  5.  //Matrix of image to be cropped
  6.  var imgMatrix= mcHolder.mcImg.transform.matrix;
  7.  //Cropped image
  8.  var myCroppedImage:Bitmap = cropImage(maskRect, imgMatrix, mcHolder.mcMask.width, mcHolder.mcMask.height,mcHolder.mcImg );
  9.  //Get new matrix of cropped image
  10.  var m:Matrix = myCroppedImage.transform.matrix;
  11.  var urlLoader:URLLoader = new URLLoader();
  12.  //Set jpg quality of the image to be export 1-100
  13.  var myEncoder:JPGEncoder = new JPGEncoder(80);
  14.  //Create jpg to be exported
  15.  var jpgSource:BitmapData = new BitmapData (mcHolder.mcMask.width, mcHolder.mcMask.height);
  16.  jpgSource.draw(myCroppedImage, m);
  17.  //Create byte array to hold jpg data
  18.  var byteArray:ByteArray = myEncoder.encode(jpgSource);
  19.  var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
  20.  //Send image to the server to be saved
  21.  var saveJPG:URLRequest = new URLRequest(_path+"saveImage.php?r="+imgID);
  22.  saveJPG.requestHeaders.push(header);
  23.  saveJPG.method = URLRequestMethod.POST;
  24.  saveJPG.data = byteArray;
  25.  urlLoader.addEventListener(Event.COMPLETE, loadCroppedImage);
  26.  urlLoader.load(saveJPG);
  27. }

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.

Get Adobe Flash player


Source example:

Credits: vamapaull, Photo Booth – Flash Webcam Image Capture (insight into export an image from Flash)

Posted in Flash AS3, Flash general, php, What i am upto | Tagged , , , , , , , , , , , | 2 Comments

Crop bitmapdata under mask to create new bitmap AS3

So you want to be able to crop an image based on what is viewable through the mask and then saved that cropped image out to a new file. For two days I played about with code to trying to get this to work. The main problem for me was that the image would be dragged about underneath the mask. This was proving a bit confusing for me in getting the coordinates to crop from. Well thankfully I was able to get it to work the way I wanted. So now that I have it working I thought I would share the code as whilst doing research for a solution I didn’t find anything of real use.

  1. function toCrop(e:Event):void {
  2.  //Matrix to holder the area to be cropped
  3.  var maskRect =mcHolder.mcMask.getBounds(mcHolder);
  4.  //Matrix of image to be cropped
  5.  var imgMatrix= mcHolder.mcImg.transform.matrix;
  6.  //Cropped image
  7.  var myCroppedImage:Bitmap = crop(maskRect, imgMatrix, mcHolder.mcMask.width, mcHolder.mcMask.height,mcHolder.mcImg );
  8.  addChild( myCroppedImage );
  9. }
  10.  
  11. function crop( rect, matrix, _width:Number, _height:Number, displayObject:DisplayObject):Bitmap {
  12.  //Create cropped image
  13.  var croppedBitmap:Bitmap = new Bitmap( new BitmapData( _width, _height ), PixelSnapping.ALWAYS, true );
  14.  croppedBitmap.bitmapData.draw(displayObject, matrix , null, null, rect, true );
  15.  return croppedBitmap;
  16. }

Here is an example:
Drag the image around then click “crop image”

Get Adobe Flash player


Source example:

Posted in Flash AS3, Flash general | Tagged , , , , , , , , , | 5 Comments