Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 739771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:26:20+00:00 2026-05-14T08:26:20+00:00

I am working with GDI+, the image I am working with is a 1bbp

  • 0

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.

public class DisplayBox : UserControl
{
    (...)
    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        (...)
            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))
                {
                    (...)
                    foreach (Epl2.IDrawableCommand cmd in Label.Collection)
                    {
                        cmd.Paint(drawBuffer);
                    }
                    (...)
                }
            }
        }
    }
}
public class InvertArea : IDrawableCommand
{
    (...)
    public Rectangle InvertRectangle {get; set;}
    public void Paint(Graphics g)
    {
        throw new NotImplementedExecption();
    }
}

What should I put in the Paint(Graphic g) for this command?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:26:20+00:00Added an answer on May 14, 2026 at 8:26 am

    The trick is to draw the same image again and use a ColorMatrix that inverts the image. For example:

        protected override void OnPaint(PaintEventArgs e) {
            e.Graphics.DrawImage(mImage, Point.Empty);
            ImageAttributes ia = new ImageAttributes();
            ColorMatrix cm = new ColorMatrix();
            cm.Matrix00 = cm.Matrix11 = cm.Matrix22 = -0.99f;
            cm.Matrix40 = cm.Matrix41 = cm.Matrix42 = 0.99f;
            ia.SetColorMatrix(cm);
            var dest = new Rectangle(50, 50, 100, 100);
            e.Graphics.DrawImage(mImage, dest, dest.Left, dest.Top, 
                dest.Width, dest.Height, GraphicsUnit.Pixel, ia);
        }
    

    Where mImage was my sample 1bpp image and I’m inverting a 100×100 rectangle at (50, 50).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the Image control to display an 8-bit grayscale image that I process
im trying to create ball animation using gdi but i can't get it working.
I'm working with a Win32 application that needs to create a variety of custom
I recently started working in VS2010 and noticed right away that the font I
Working with an API that can handle multiple connections (i.e. sessions), each of these
I haven't written anything with GDI for a while now (and never with GDI+),
I have a live 16-bit gray-scale video stream that is pushed through a ring-buffer
I am porting a GDI application over to WPF, where I displayed several dozen
I'm painting this object in C# using GDI and I need to have precise
I did nice winforms 2.0 application and it's working great and customers are still

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.