Comparing two images from the clipboard class

Posted by VeXe on Stack Overflow See other posts from Stack Overflow or by VeXe
Published on 2012-12-08T17:02:37Z Indexed on 2012/12/08 17:03 UTC
Read the original article Hit count: 257

Filed under:
|
|

In a C# winform app. I'm writing a Clipboard log manager that logs test 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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about clipboard