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 6075847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:32:24+00:00 2026-05-23T10:32:24+00:00

I have a image loaded in picturebox.I perform a paint operation on the image,

  • 0

I have a image loaded in picturebox.I perform a paint operation on the image, by the mouseclick event.It paints a small rectangular area with black color, when the mouse is clicked at that point.now I want to implement the undo operation for this .When i click a button the last paint operation should be undone.Here is my code for paint operation..

      private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
    {

            rect.Width = 0;
            rect.Height = 0;
            pictureBox1.Invalidate();


            int radius = 10; //Set the number of pixel you want to use here
            //Calculate the numbers based on radius
            int x0 = Math.Max(e.X - (radius / 2), 0),
                y0 = Math.Max(e.Y - (radius / 2), 0),
                x1 = Math.Min(e.X + (radius / 2), pictureBox1.Width),
                y1 = Math.Min(e.Y + (radius / 2), pictureBox1.Height);
            Bitmap bm = pictureBox1.Image as Bitmap; //Get the bitmap (assuming it is stored that way)
            for (int ix = x0; ix < x1; ix++)
            {
                for (int iy = y0; iy < y1; iy++)
                {
                    bm.SetPixel(ix, iy, Color.Black); //Change the pixel color, maybe should be relative to bitmap
                }
            }
            pictureBox1.Refresh(); //Force refresh
          }

Any one please help me how i can undo the last operation performed.

  • 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-23T10:32:25+00:00Added an answer on May 23, 2026 at 10:32 am

    Because you’re working with raster image in memory you cannot just undo the operation. There can be multiple solutions to this:

    1. Keep the original image in memory and for each operation keep the drawing parameters: what was drawn, where, which color. When you will need an undo you will just have to repeat all the operation from the first to last (you may also have a control points where you store an intermediate image)
    2. After each operation keep the snapshot of the image – this will be very memory consuming. On undo – restore the previous picture in the list.
    3. Keep the changed pixels – on each operation analyze the previous image and new one and keep the pixels changes. You will be able to revert to previous by copying those pixels back.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have loaded the image to picturebox in zoom mode. but the text is not
I have an image loaded by JS on a mouse event. It's a fairly
I have a UIImageView which has a png image sequence loaded into it. My
I have loaded an byte array image from a web service to my asp.net
I have to implement an Image Gallery for the iPhone iOS. Pictures are loaded
I Want to load Image size 2550X3300 (i.e 1.7 Mb size), i have loaded
Hi iam new to C# and have loaded the image in the picture box
I have an image loaded into an Image control and I'd like to know
So ... I have an image loaded into an NSBitmapImageRep object, so I am
I have a image loaded in a sprite, the image is from a remote

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.