How To

So, here we gonna describe how to create your own sample!
Full code at the bottom of the Page!

Simple Sample
First you have to create a new Replacer or an implementation of that (VektorRecogniser)

//Create a new Replacer
var r = new Replacer();
After that you have to set up the Picture which will be manipulated (If you're picture has an 8bpp Indexed Format, you have to convert it!)

//Load an Image
r.Picture = (Bitmap)Bitmap.FromFile("myimage.png", true);
Then you have to create a rule, and set up the pixel ranges (filters) for every color (A = Alpha, R = Red, G = Green, B = Blue)

//Create a new Rule
PixelRule myrule = new PixelRule();

//Give it a Name
myrule.Name = "Test Rule";

//Set Up the Filter Values
myrule.A = new PixelRange(0, 256);
myrule.R = new PixelRange(10, 50);
myrule.G = new PixelRange(100, 120);
myrule.B = new PixelRange(0, 200);

//And the new Color
myrule.NewColor = Color.Orange;
After this step, you have to add the Rule to the Replacer we created before and let the Replacer do his work

//Add the Rule to the Replacer
r.Rules.Add(myrule);

//Recognize the Image
r.Recognize();
Now you can save the final picture into a new image and you have filtered your own image, with the Pixel Replacer

//Save Filtered BMP
Bitmap filteredbmp = (Bitmap)r.Picture.Clone();
filteredbmp.Save("myfiltered.bmp", ImageFormat.Bmp);

Full Code

//Create a new Replacer
var r = new Replacer();

//Load an Image
r.Picture = (Bitmap)Bitmap.FromFile("myimage.png", true);

//Create a new Rule
PixelRule myrule = new PixelRule();

//Give it a Name
myrule.Name = "Test Rule";

//Set Up the Filter Values
myrule.A = new PixelRange(0, 256);
myrule.R = new PixelRange(10, 50);
myrule.G = new PixelRange(100, 120);
myrule.B = new PixelRange(0, 200);

//And the new Color
myrule.NewColor = Color.Orange;

//Add the Rule to the Replacer
r.Rules.Add(myrule);

//Recognize the Image
r.Recognize();

//Save Filtered BMP
Bitmap filteredbmp = (Bitmap)r.Picture.Clone();
filteredbmp.Save("myfiltered.bmp", ImageFormat.Bmp);

Last edited Jan 29, 2011 at 10:19 PM by cansik, version 11

Comments

No comments yet.