{"id":125,"date":"2007-05-26T15:08:12","date_gmt":"2007-05-26T06:08:12","guid":{"rendered":"http:\/\/hangunsworld.com\/blog\/?p=125"},"modified":"2008-05-16T09:37:36","modified_gmt":"2008-05-16T00:37:36","slug":"as3-chromaque-effect","status":"publish","type":"post","link":"http:\/\/hangunsworld.com\/blog\/125","title":{"rendered":"[AS3] Chromaque effect"},"content":{"rendered":"<p><embed src=\"\/blog\/wp-content\/uploads\/2007\/05\/chromaque.swf\" title=\"Chromaque effect\" height=\"360\" width=\"450\"><\/embed><br \/>\n<!--more--><\/p>\n<pre lang=\"ActionScript3\" line=\"1\">\/*\r\n * This work is licensed under a Creative Commons Attribution 3.0 License.\r\n * http:\/\/creativecommons.org\/licenses\/by\/3.0\/\r\n *\/\r\n\r\n\/*\r\n * Chromaque\r\n * Chromaque class combines two images\r\n * Pixels with the specifics color will be replaced with pixels of a target image\r\n *\r\n * @author: Han Sanghun (http:\/\/hangunsworld.com\/blog)\r\n * @last modified: 2007-05-26\r\n * @language version: ActionScript 3.0\r\n *\/\r\n\r\npackage{\r\n\r\n\timport\tflash.display.*;\r\n\timport\tflash.geom.*;\r\n\r\n\tpublic class Chromaque extends MovieClip{\r\n\r\n\t\t\/\/ image dimmesions\r\n\t\tprivate const WID:uint = 139;\r\n\t\tprivate const HGT:uint = 173;\r\n\r\n\t\t\/\/ original bitmapData\r\n\t\tprivate var ori_bd:BitmapData;\r\n\t\tprivate var ori_bmp:Bitmap;\r\n\r\n\t\t\/\/ target bitmapData\r\n\t\tprivate var image_bd:BitmapData;\r\n\r\n\t\t\/\/ rectangles\r\n\t\tprivate var rect:Rectangle;\r\n\t\tprivate var pnt:Point;\r\n\t\tprivate var area_rect:Rectangle;\r\n\t\tprivate var area_mc:MovieClip;\r\n\r\n\t\t\/\/ chrom bitmapData\r\n\t\tprivate var chrom_bd:BitmapData;\r\n\t\tprivate var chrom_bmp:Bitmap;\r\n\t\t\/\/ result bitmapData\r\n\t\tprivate var result_bd:BitmapData;\r\n\t\tprivate var result_bmp:Bitmap;\r\n\r\n\t\t\/\/ color to be replaced\r\n\t\tvar chromColor:uint = 0xFFD9D9D9;\r\n\r\n\t\t\/*\r\n\t\t * Chromaque class constructor\r\n\t\t *\/\r\n\t\tpublic function Chromaque(){\r\n\r\n\t\t\t\/\/ draw original image\r\n\t\t\tori_bd = new BitmapData(WID, HGT, true, 0\u00d700000000);\r\n\t\t\tori_bd.draw(source1_mc);\r\n\t\t\tori_bmp = new Bitmap(ori_bd);\r\n\t\t\taddChild(ori_bmp);\r\n\t\t\tori_bmp.y = 180;\r\n\r\n\t\t\t\/\/ draw target image\r\n\t\t\timage_bd = new BitmapData(WID, HGT, true, 0\u00d700000000);\r\n\t\t\timage_bd.draw(source2_mc);\r\n\r\n\t\t\t\/\/ create chrom bitmapDate\r\n\t\t\t\/\/ you can use chrom as a mask\r\n\t\t\tchrom_bd = new BitmapData(WID, HGT, true, 0\u00d700000000);\r\n\t\t\t\/\/ clone original bitmapDate\r\n\t\t\tresult_bd = ori_bd.clone();\r\n\r\n\t\t\t\/\/ get rectangle filled with the color to be replaced\r\n\t\t\tarea_rect = ori_bd.getColorBoundsRect(0xFFFFFFFF, chromColor, true);\r\n\t\t\t\/\/ show me the area\r\n\t\t\tarea_mc = new MovieClip();\r\n\t\t\tarea_mc.y = 180;\r\n\t\t\tarea_mc.graphics.clear();\r\n\t\t\tarea_mc.graphics.beginFill(0xFF0000, .5);\r\n\t\t\tarea_mc.graphics.drawRect(area_rect.x, area_rect.y, area_rect.width, area_rect.height);\r\n\t\t\tarea_mc.graphics.endFill();\r\n\t\t\taddChild(area_mc);\r\n\r\n\t\t\t\/\/ area_rect is used in order to minimize the \u201cfor\u201d roof\r\n\t\t\tvar startX:uint = area_rect.x;\r\n\t\t\tvar startY:uint = area_rect.y;\r\n\t\t\tvar endX:uint = startX + area_rect.width;\r\n\t\t\tvar endY:uint = startY + area_rect.height;\r\n\r\n\t\t\t\/\/ lock up bitmapData\r\n\t\t\tchrom_bd.lock();\r\n\t\t\tresult_bd.lock();\r\n\r\n\t\t\tfor(var i:uint=startX; i<=endX; i++){\r\n\t\t\t\tfor(var k:uint=startY; k<=endY; k++){\r\n\t\t\t\t\t\/\/ when the color matchs the chromColor\r\n\t\t\t\t\tif(ori_bd.getPixel32(i, k) == chromColor){\r\n\t\t\t\t\t\t\/\/ paint chrom with red\r\n\t\t\t\t\t\tchrom_bd.setPixel32(i, k, 0xFFFF0000);\r\n\t\t\t\t\t\t\/\/ paint result with target image\r\n\t\t\t\t\t\tresult_bd.setPixel32(i, k, image_bd.getPixel32(i, k));\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t\/\/ unlock bitmapData\r\n\t\t\tchrom_bd.unlock();\r\n\t\t\tresult_bd.unlock();\r\n\r\n\t\t\t\/\/ display chrom\r\n\t\t\tchrom_bmp = new Bitmap(chrom_bd);\r\n\t\t\taddChild(chrom_bmp);\r\n\t\t\tchrom_bmp.x = 150;\r\n\t\t\tchrom_bmp.y = 180;\r\n\r\n\t\t\t\/\/ display result\r\n\t\t\tresult_bmp = new Bitmap(result_bd);\r\n\t\t\taddChild(result_bmp);\r\n\t\t\tresult_bmp.x = 300;\r\n\t\t\tresult_bmp.y = 180;\r\n\r\n\t\t}\/\/ end of Chromaque\r\n\r\n\t}\/\/ end of class\r\n\r\n}\/\/ end of package<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[30],"class_list":["post-125","post","type-post","status-publish","format-standard","hentry","category-as3","tag-bitmapdata"],"_links":{"self":[{"href":"http:\/\/hangunsworld.com\/blog\/wp-json\/wp\/v2\/posts\/125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/hangunsworld.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/hangunsworld.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/hangunsworld.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/hangunsworld.com\/blog\/wp-json\/wp\/v2\/comments?post=125"}],"version-history":[{"count":0,"href":"http:\/\/hangunsworld.com\/blog\/wp-json\/wp\/v2\/posts\/125\/revisions"}],"wp:attachment":[{"href":"http:\/\/hangunsworld.com\/blog\/wp-json\/wp\/v2\/media?parent=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/hangunsworld.com\/blog\/wp-json\/wp\/v2\/categories?post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/hangunsworld.com\/blog\/wp-json\/wp\/v2\/tags?post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}