{"id":239,"date":"2009-04-01T09:55:38","date_gmt":"2009-04-01T16:55:38","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1093"},"modified":"2009-04-01T09:55:38","modified_gmt":"2009-04-01T16:55:38","slug":"save-bitmapdata-to-your-hd","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=239","title":{"rendered":"Save BitmapData to your HD"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.adobe.images.JPGEncoder;\r\n\r\nvar jpgEncoder:JPGEncoder = new JPGEncoder(80);\r\nvar file:FileReference = new FileReference();\r\nvar id:int = 0;\r\n\r\nvar bit:BitmapData = new BitmapData(400, 400, false, 0x000000);\r\naddChild(new Bitmap(bit));\r\n\r\nstage.addEventListener(MouseEvent.CLICK, onClick);\r\nfunction onClick(evt:MouseEvent):void{\r\n\t\/\/ draw some perlin noise\r\n\tbit.perlinNoise(200,200, 2, Math.random()*100, true, false,0, true);\r\n\t\/\/bit.draw(someClip);\r\n\t\/\/bit.draw(someVideo);\r\n\tid++;\r\n\tfile.save(jpgEncoder.encode(bit), &quot;image_&quot; +id+&quot;.jpg&quot;);\r\n}\r\n<\/pre>\n<p>This snippet uses the as3corelib which you can download <a href=\"http:\/\/code.google.com\/p\/as3corelib\/\">on this page<\/a>. 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.<\/p>\n<p>I used BitmapData.perlinNoise() to quickly create an arbitrary image&#8230;. as the code comments suggest you could easily snapshot a video or other DisplayObject.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>import com.adobe.images.JPGEncoder; var jpgEncoder:JPGEncoder = new JPGEncoder(80); var file:FileReference = new FileReference(); var id:int = 0; var bit:BitmapData = new BitmapData(400, 400, false, 0x000000); addChild(new Bitmap(bit)); stage.addEventListener(MouseEvent.CLICK, onClick); function onClick(evt:MouseEvent):void{ \/\/ draw some perlin noise bit.perlinNoise(200,200, 2, Math.random()*100, true, false,0, true); \/\/bit.draw(someClip); \/\/bit.draw(someVideo); id++; file.save(jpgEncoder.encode(bit), &quot;image_&quot; +id+&quot;.jpg&quot;); } This snippet uses the as3corelib which you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,94],"tags":[3,4],"class_list":["post-239","post","type-post","status-publish","format-standard","hentry","category-bitmapdata","category-misc","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/239","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=239"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/239\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}