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

  • Home
  • SEARCH
  • 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 8954241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:16:38+00:00 2026-06-15T14:16:38+00:00

In a C# winform app. I’m writing a Clipboard log manager that logs text

  • 0

In a C# winform app. I’m writing a Clipboard log manager that logs text to a log file, (everytime a Ctrl+c/x is pressed the copied/cut text gets appended to the file)
I also did the same for images, that is, if you press “prtScreen”, the screen shot you took will also go to a folder.

I do that by using a timer, inside I have something which ‘looks’ like this:

if (Clipboard.ContainsImage())
{
  if (IsClipboardUpdated())
  {
    LogData();
    UpdateLastClipboardData();
  }
}

This is how the rest of the methods look like:

public void UpdateLastClipboardData()
{
  // ... other updates
  LastClipboardImage = Clipboard.GetImage();
}
// This is how I determine if there's a new image in the clipboard...
public bool IsClipboardUpdated()
{
  return (LastClipboardImage != Clipboard.GetImage());
}
public void LogData()
{
  Clipboard.GetImage().Save(ImagesLogFolder + "\\Image" + now_hours + "_" + now_mins + "_" + now_secs + ".jpg");  
}

The problem is: inside the update method, “LastClipboardImage != Clipboard.GetImage()” is always returning true!

I even did the following inside the update method:

Image img1 = Clipboard.GetImage();
Image img2 = Clipboard.GetImage();
Image img3 = img2;
bool b1 = img1 == img2; // this returned false. WHY??
bool b2 = img3 == img2; // this returned true. Makes sense.

Please help, the comparison isn’t working… why?

  • 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-06-15T14:16:40+00:00Added an answer on June 15, 2026 at 2:16 pm

    A little test. Call two times the GetImage method for the same image

    void Main()
    {
        Image bmp1 = Clipboard.GetImage();
        Image bmp2 = Clipboard.GetImage();
    
        if(bmp1 != null && bmp1 == bmp2)
            Console.WriteLine("True");
        else
            Console.WriteLine("False");
    }
    

    it returns always false. So every time you call Clipboard.GetImage() you get a different image instance and thus you cannot compare then using a simple == operator

    You are comparing two different instances of an Image object and of course they are not the same.

    If you really want to compare the image down to the pixel level you need a more invasive (and performance hungry method) like this

    bool ImagesAreDifferent(Image img1, Image img2)
    {
        Bitmap bmp1 = new Bitmap(img1);
        Bitmap bmp2 = new Bitmap(img2);
    
        bool different = false;
        if (bmp1.Width == bmp2.Width && bmp1.Height == bmp2.Height)
        {
            for (int i = 0; i < bmp1.Width; i++)
            {
                for (int j = 0; j < bmp1.Height; j++)
                {
                    Color col1 = bmp1.GetPixel(i, j);
                    Color col2 = bmp2.GetPixel(i, j);
                    if (col1 != col2)
                    {
                        i = bmp1.Width + 1;
                        different = true;
                        break;
                    }
                }
            }
        }    
        return different;
    }
    

    Notice how this is possible because the Color structure defines an Equality operator that checks if the color RGB values are the same between two colors

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

Sidebar

Related Questions

i have a winform app that contains a form1 and the program.cs file. in
Hello I have a WinForm app that generates a ton of data. Currently I
I have a winform app that has tabcontrols that are 3 layers deep. I
I have a winform app that fills a lot of its dropdomn fields fram
I have a Winform App that uses a 3rd Party Library of Controls, DevExpress.
I have a medium sized WinForm App ( 1 Form that hosts 40 user
I'm creating winForm app,In that Onbutton click i gather Data Tables from of Two
I have Winform app I am writing in C#. On my form, I have
I have a WinForm app that displays results in a Gridview control. If a
We have a winform app that has been in development for some time. It

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.