Tato aplikace používá algoritmus Flood Fill od Justina Dunlapa
Třídy které implementují algoritmus Flood fill
AbstractFloodFiller.cs
FloodFiller.cs
Vyplnit oblast je velice snadné
Pro vyplnění oblasti je nutné získat pozici myši na kterou uživatel kliknul - zbytek zajistí algoritmus.
private void pbx_MouseDown(object sender, System.Windows.Forms.MouseEventArgs ev)
{
if (ev.Button==System.Windows.Forms.MouseButtons.Left) //if the left button was pressed
{
//get the actual point that was clicked on the bitmap
Point Pt=new Point(ev.X,ev.Y);
Pt.X%= m_PictureBox.Width;
Pt.Y%= m_PictureBox.Height;
//initialize the data - we can't pass it directly
m_FloodFiller.Pt=Pt;
Bitmap b=null;
b=(Bitmap)m_PictureBox.Image;
if ( b.Width < ev.X ) return;
if ( b.Height < ev.Y ) return; PlaySndColoringClick();
m_FloodFiller.FloodFill(b,Pt);
this.m_PictureBox.Refresh();
}
}
// Pro přehrání zvuků
public class WinSound
{
[DllImport("WinMM.dll")]
public static extern bool PlaySound(string fname, int Mod, int flag);
//SoundFlags
// play asynchronously
public int SND_ASYNC = 0x0001;
// file name
public int SND_FILENAME = 0x00020000;
// purge non-static events
public int SND_PURGE = 0x0040;
public void Play(string fname, int SoundFlags)
{
PlaySound(fname, 0, SoundFlags);
}
public void StopPlay()
{
PlaySound(null, 0, SND_PURGE);
}
}