Hi rangasamy,
I've been doing something very simillar - I've given a brief overview of how I've done it below. I'm assuming you're using a standard scanned form, so the fields being redacted will be in a constant position. I'm not sure it would be possible if the details could be anywhere on the image (OCR maybe?)
The simplest way seems to be using the GdViewer to draw a region on a loaded image, then storing the settings for future use (database, xml, text file, etc...).
Drawing Regions:
- Code: Select all
// set the viewer to allow a region to be selected by clicking and dragging
gdViewer1.MouseMode = ViewerMouseMode.MouseModeAreaSelection;
...
// Wait for the mouse up event - indicates that a region has been drawn
private void gdViewer1_MouseUp(object sender, MouseEventArgs e) {
// check a rectangle has been drawn
if (gdViewer1.IsRect()) {
int t_left = 0;
int t_top = 0;
int t_width = 0;
int t_height = 0;
// get the co-ordinates / size of the drawn area
gdViewer1.GetRectCoordinatesOnDocument(ref t_left, ref t_top, ref t_width, ref t_height);
}
}
With the area set, we can then draw the rectangle onto the viewer. This displays a rectangle, without actually altering the underlying image.
- Code: Select all
gdViewer1.AddRegion("Redaction", t_left, t_top, t_width, t_height, ForegroundMixMode.ForegroundMixModeBLACK, Color.Black);
gdViewer1.Redraw();
To Clear the rectangle:
- Code: Select all
gdViewer1.ClearRect();
gdViewer1.RemoveAllRegions();
So far none of this has altered the underlying image. If the user is happy with the redactions, they can be drawn onto the image:
- Code: Select all
// draw rectangle onto image
ogdPictureImaging.DrawFilledRectangle(image1, t_left, t_top, t_width, t_height, Color.Black)
This is now part of the image, and is basically unremovable.
Obviously you can extend this to allow as many redactions as you wish. I work on a sample image to get the settings, then save them for future use. These can then be added automatically (using drawFilledRectangle(...), or displayed for user confirmation / editing (gdViewer.AddRegion(...)).
You'll probably need at least some sort of manual validation for automatic validation. Theres nothing worse than displaying the functionality to a client and discovering someones ignored the appropriate box and written their credit-card number across the top of the form (true story!). I tend to display the redactions on screen, then allow the user to either accept them, or edit/remove them if needed.
Also, as this is all location based off a 'perfect' sample image, it will throw off the redaction if the images vary in size. I use a very basic modifier that checks the size of the image against the sample, and resizes/relocates the redaction areas accordingly. This works for small variations, but will fail if the image is a very different size.
I hope this helps, but I'd be very interested to know if anyone can come up with better ways of doing this!