Click here to Skip to main content
12,814,994 members (36,162 online)
Click here to Skip to main content
Articles » Multimedia » GDI+ » General » Downloads


56 bookmarked
Posted 15 Nov 2006

Queue-Linear Flood Fill: A Fast Flood Fill Algorithm

, 15 Nov 2006
A super-fast flood fill algorithm and implementation, plus helpful optimization tips for image processing.
using System;
using System.Drawing;

namespace FloodFill2
    /// <summary>A queue of FloodFillRanges.</summary>
	public class FloodFillRangeQueue
        FloodFillRange[] array;
        int size;
        int head;

        /// <summary>
        /// Returns the number of items currently in the queue.
        /// </summary>
        public int Count
            get { return size; }

		public FloodFillRangeQueue():this(10000)


        public FloodFillRangeQueue(int initialSize)
            array = new FloodFillRange[initialSize];
            head = 0;
            size = 0;

        /// <summary>Gets the <see cref="FloodFillRange"/> at the beginning of the queue.</summary>
        public FloodFillRange First 
			get { return array[head]; }

        /// <summary>Adds a <see cref="FloodFillRange"/> to the end of the queue.</summary>
        public void Enqueue(ref FloodFillRange r) 
			if (size+head == array.Length) 
                FloodFillRange[] newArray = new FloodFillRange[2 * array.Length];
                Array.Copy(array, head, newArray, 0, size);
				array = newArray;
                head = 0;
            array[head+(size++)] = r;

        /// <summary>Removes and returns the <see cref="FloodFillRange"/> at the beginning of the queue.</summary>
        public FloodFillRange Dequeue() 
            FloodFillRange range = new FloodFillRange();
            if (size>0)
                range = array[head];
                array[head] = new FloodFillRange();
                head++;//advance head position
                size--;//update size to exclude dequeued item
            return range;

        /// <summary>Remove all FloodFillRanges from the queue.</summary>
		/*public void Clear() 
			if (size > 0)
				Array.Clear(array, 0, size);
			size = 0;


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

J. Dunlap
Web Developer
United States United States
My main goal as a developer is to improve the way software is designed, and how it interacts with the user. I like designing software best, but I also like coding and documentation. I especially like to work with user interfaces and graphics.

I have extensive knowledge of the .NET Framework, and like to delve into its internals. I specialize in working with and MyXaml. I also like to work with ASP.NET, AJAX, and DHTML.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 15 Nov 2006
Article Copyright 2006 by J. Dunlap
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid