+ Reply to Thread
Results 1 to 4 of 4

Coloring regions of images

This is a discussion on Coloring regions of images within the Tutorials forums, part of the Flash English category; In this tutorial we see how to color the sections of an image using the method floodFill() of the BitmapData ...

  1. #1
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,762
    Rep Power
    11

    Coloring regions of images

    In this tutorial we see how to color the sections of an image using the method floodFill() of the BitmapData class of Actionscript 3.0.

    This method works almost like magic wand tool in Photoshop (or other photo editor) with a setting of zero tolerance.

    It fills in all contiguous regions of the same pixel color with the specified color.


    This method allows us to create such an application of coloring and much more.


    The example that I created works with an external black and white GIF image.

    The image has been loaded into Flash and with a ColorPicker component, check the color you will use to fill in certain areas of the image.


    For example, choose a color and click to image's area.









    Actionscript


    Code:
    package
    {
    	import flash.display.*;
    	import flash.events.*;
    	import flash.net.*;
    	import flash.geom.*;
    	
    	public class Main extends MovieClip
    	{
    		private var bitmap:Bitmap;
    		private var bitmapdata:BitmapData;
    		
    		private var holder_mc:MovieClip;
    		
    		private var current_color:uint=0;
    		
    		public function Main()
    		{
    			addEventListener(Event.ADDED_TO_STAGE,init);
    		}
    		
    		private function init(evt:Event):void
    		{
    			removeEventListener(Event.ADDED_TO_STAGE,init);
    			
    			reset_btn.label="RESET";
    			
    			loadImage();
    		}
    		
    		private function loadImage():void
    		{
    			if(holder_mc!=null)
    			{
    				removeChild(holder_mc);
    				bitmapdata.dispose();
    				bitmap=null;
    				holder_mc=null;
    			}
    			var request:URLRequest=new URLRequest("jerry.gif");
    			var loader:Loader=new Loader();
    			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onImageLoaded);
    			loader.load(request);
    		}
    		
    		private function onImageLoaded(evt:Event):void
    		{
    			bitmap=evt.target.loader.content as Bitmap;
    			bitmapdata=bitmap.bitmapData;
    			holder_mc=new MovieClip();
    			holder_mc.addChild(bitmap);
    			addChild(holder_mc);
    			
    			addListeners();
    		}
    		
    		private function addListeners():void
    		{
    			color_picker.addEventListener(Event.CHANGE,onColorChange);
    			
    			holder_mc.mouseChildren=false;
    			//holder_mc.buttonMode=true;
    			holder_mc.addEventListener(MouseEvent.MOUSE_DOWN, paint);
    			
    			reset_btn.addEventListener(MouseEvent.MOUSE_DOWN,reset);
    		}
    		
    		private function onColorChange(evt:Event):void
    		{
    			current_color=evt.target.selectedColor;
    		}
    		
    		private function paint(evt:MouseEvent):void
    		{
    			var xx:Number=evt.localX;
    			var yy:Number=evt.localY;
    			bitmapdata.floodFill(xx,yy,current_color);
    		}
    		
    		private function reset(evt:MouseEvent):void
    		{
    			loadImage();
    		}
    	}
    }
    Source files:
    Attached Files

  2. #2
    Junior Member Settled In mikyun_patel13 is on a distinguished road
    Join Date
    Jul 2010
    Posts
    1
    Rep Power
    0

    Re: Coloring regions of images

    thanks
    this one is great

  3. #3
    Junior Member Settled In yasdar2002 is on a distinguished road
    Join Date
    Dec 2011
    Posts
    1
    Rep Power
    0

    Re: Coloring regions of images

    Hi nice work
    ls I want to understand why when I use your file jerry.gif everything work very well , but if i use one of my image (gif, jpeg or png) , the flash doesn't work very well ?
    Thanks
    Untitled.png

  4. #4
    Junior Member Settled In davis123 is on a distinguished road
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Re: Coloring regions of images

    Flash web development services of this Flash development company constitute the following:

    Multi layered business solutions for small, medium and large enterprises.
    Original and creative Flash designs that attract and engage visitors
    Effective Flash software development and rich multimedia solutions to present clients successfully to their target customers
    Brand positioning, promotion and growth through effective designs that pull traffic and facilitate client conversion


    flash web development company

+ Reply to Thread

Similar Threads

  1. Images Scroller
    By Flep in forum FlepStudio utilities
    Replies: 64
    Last Post: 31-01-13, 15:09
  2. Images Scroller version 4
    By Flep in forum FlepStudio utilities
    Replies: 7
    Last Post: 11-07-11, 14:20
  3. bitmap images using flash as2 or as3
    By kamal in forum Flash English
    Replies: 2
    Last Post: 27-09-10, 18:50
  4. Caricare images da xml
    By nocciola in forum Actionscript 3.0 avanzato
    Replies: 0
    Last Post: 12-04-09, 07:13
  5. unload images
    By karonte in forum Actionscript 3.0 base
    Replies: 2
    Last Post: 14-05-08, 19:01

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts