{"id":478,"date":"2011-11-11T14:46:27","date_gmt":"2011-11-11T13:46:27","guid":{"rendered":"http:\/\/www.aymericlamboley.fr\/blog\/?p=478"},"modified":"2011-11-11T14:46:27","modified_gmt":"2011-11-11T13:46:27","slug":"playing-with-bitmapdata","status":"publish","type":"post","link":"http:\/\/www.aymericlamboley.fr\/blog\/playing-with-bitmapdata\/","title":{"rendered":"Playing with BitmapData"},"content":{"rendered":"<p>At school, we made a cool exercise on Bitmap &#038; BitmapData. That was great, I don&#8217;t work a lot with them.<br \/>\nThe goal was to repeat a picture (make it roll and apply a blur) an on an enter frame without performance drop!<\/p>\n<p>Nothing too complex, but a really nice post-it \ud83d\ude09<\/p>\n<p><a href=\"http:\/\/www.aymericlamboley.fr\/blog\/wp-content\/uploads\/2011\/11\/BitmapData.swf\" rel=\"lightbox[flash 550 400]\" title=\"BevelFilters\">Click here to see the result<\/a>.<\/p>\n<pre lang='actionscript3\" line=\"1\">import flash.display.Bitmap;\r\nimport flash.display.BitmapData;\r\nimport flash.display.MovieClip;\r\nimport flash.events.Event;\r\nimport flash.geom.Matrix;\r\nimport flash.geom.Point;\r\nimport flash.geom.Rectangle;\r\n\r\nvar bmpDataStage:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0);\r\nbmpDataStage.draw(stage);\r\n\r\nvar bmpStage:Bitmap = new Bitmap(bmpDataStage);\r\naddChild(bmpStage);\r\n\r\n\/\/ Coming from the flash library\r\nvar flower:Flower = new Flower();\r\n\r\nvar bmpDataFlower:BitmapData = new BitmapData(flower.width, flower.height, true, 0);\r\nbmpDataFlower.draw(flower);\r\n\r\nvar time:Number = 0;\r\n\r\naddEventListener(Event.ENTER_FRAME, ef);\r\n\r\nfunction ef(evt:Event):void {\r\n\t\r\n\ttime += 0.3;\r\n\t\r\n\tvar mat:Matrix = new Matrix();\r\n\tmat.translate(-flower.width * 0.5, -flower.height * 0.5);\r\n\tmat.rotate(time);\r\n\tmat.translate(flower.width * 0.5, flower.height * 0.5);\r\n\t\r\n\tbmpDataFlower.fillRect(new Rectangle(0, 0, flower.width, flower.height), 0x00000000);\r\n\tbmpDataFlower.draw(flower, mat);\r\n\t\r\n\tbmpDataFlower.applyFilter(bmpDataFlower, bmpDataFlower.rect, new Point(0, 0), getBitmapFilter());\r\n\t\r\n\tbmpDataStage.copyPixels(bmpDataFlower, bmpDataStage.rect, new Point(mouseX - flower.width * 0.5, mouseY - flower.height * 0.5), null, null, true);\r\n}\r\n\r\nfunction getBitmapFilter():BitmapFilter {\r\n\tvar blurX:Number = 5;\r\n\tvar blurY:Number = 5;\r\n\treturn new BlurFilter(blurX, blurY, BitmapFilterQuality.HIGH);\r\n}<\/pre>\n<p>In a next lesson, we will see Blitting&#8230; can&#8217;t wait!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>At school, we made a cool exercise on Bitmap &#038; BitmapData. That was great, I don&#8217;t work a lot with them. The goal was to repeat a picture (make it roll and apply a blur) an on an enter frame without performance drop! Nothing too complex, but a really nice post-it \ud83d\ude09 Click here to &hellip; <a href=\"http:\/\/www.aymericlamboley.fr\/blog\/playing-with-bitmapdata\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Playing with BitmapData<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[4,33],"tags":[15,95,96,34],"_links":{"self":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts\/478"}],"collection":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/comments?post=478"}],"version-history":[{"count":2,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts\/478\/revisions"}],"predecessor-version":[{"id":480,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts\/478\/revisions\/480"}],"wp:attachment":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/media?parent=478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/categories?post=478"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/tags?post=478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}