Invert the 1bbp color under a rectangle.
Posted
by Scott Chamberlain
on Stack Overflow
See other posts from Stack Overflow
or by Scott Chamberlain
Published on 2010-04-16T21:30:49Z
Indexed on
2010/04/16
21:33 UTC
Read the original article
Hit count: 244
I am working with GDI+, the image I am working with is a 1bbp image. What i would like to do is draw a rectangle on the image and everything under that rectangle will be inverted (white pixels will become black and black pixels become white).
All of the sample code I have seen is for 8 bit RGB color scale images, and I don't think the techniques they use will work for me.
Here is the code I have so far. This is the parent control, one of the Epl2.IDrawableCommand
's will be the command that does the inverting.
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (Label != null)
{
using (Bitmap drawnLabel = new Bitmap((int)((float)Label.LabelHeight * _ImageScaleFactor), (int)((float)Label.LableLength *(int) _ImageScaleFactor), System.Drawing.Imaging.PixelFormat.Format1bppIndexed))
{
using (Graphics drawBuffer = Graphics.FromImage(drawnLabel))
{
drawBuffer.ScaleTransform(_ImageScaleFactor, _ImageScaleFactor);
foreach (Epl2.IDrawableCommand cmd in Label.Collection)
{
cmd.Paint(drawBuffer);
}
drawBuffer.ResetTransform();
}
drawnLabel.RotateFlip(Rotation);
pbLabelDrawArea.Size = drawnLabel.Size;
using (Graphics drawArea = pbLabelDrawArea.CreateGraphics())
{
drawArea.Clear(Color.White);
drawArea.DrawImage(drawnLabel, new Point(0, 0));
}
}
}
}
What should I put in the Paint(Graphic g)
for this command?
© Stack Overflow or respective owner