Save BitmapData to your HD

Actionscript:
  1. import com.adobe.images.JPGEncoder;
  2.  
  3. var jpgEncoder:JPGEncoder = new JPGEncoder(80);
  4. var file:FileReference = new FileReference();
  5. var id:int = 0;
  6.  
  7. var bit:BitmapData = new BitmapData(400, 400, false, 0x000000);
  8. addChild(new Bitmap(bit));
  9.  
  10. stage.addEventListener(MouseEvent.CLICK, onClick);
  11. function onClick(evt:MouseEvent):void{
  12.     // draw some perlin noise
  13.     bit.perlinNoise(200,200, 2, Math.random()*100, true, false,0, true);
  14.     //bit.draw(someClip);
  15.     //bit.draw(someVideo);
  16.     id++;
  17.     file.save(jpgEncoder.encode(bit), "image_" +id+".jpg");
  18. }

This snippet uses the as3corelib which you can download on this page. It uses the JPGEncoder class to save a jpeg image to a users HD. It also makes use of the flash player 10 FileReference.save() method.

I used BitmapData.perlinNoise() to quickly create an arbitrary image.... as the code comments suggest you could easily snapshot a video or other DisplayObject.

This entry was posted in BitmapData, misc and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment

  1. Posted March 2, 2010 at 9:17 am | Permalink

    Is this only available in CS4? I don’t see a reference to FileReference.save in the help of my CS3

2 Trackbacks

  1. [...] Save BitmapData to your HD [...]

  2. [...] mit einem Skript. Wei

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*