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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:15:43+00:00 2026-05-25T03:15:43+00:00

I am not sure if my problem is platform specific, but I think it

  • 0

I am not sure if my problem is platform specific, but I think it is not.
Because my expirience is based on the Windows specific java.awt.Toolkit and the Windows-Clipboard.

The following example class shows the problem i am faced with.
NOTE: Before running the program, make sure you have no Image in you system clipboard.

If there is no Image in the system clipboard the Program put a new screenshot to it.

Then I get the Clipboard data two times!

All 3 Images are equal! – the original Screenshot and every Image I get from the clipboard.
which is ok.

But now running the program a second time.
NOTE: There is the old screenshot in the clipboard!

The Program generates a new screenshot and get the old one from the clipboard two times.

No Images is equal to any! – The first (new screenshot) should be not equal, it is okay

But every next Image I get is not equal.

Q1: If every next Image I get is not equal, why it was equal at the first time?
Q2: The bigger Question: How can I compare a java.awt.Image to get every next Image equal.

I am looking for an easy and fast comparison of two Images or an easy way to figure out that the clipboard doesn’t has changed.

public class Example {

    public static void main( String[] args ) throws Exception {

        final Toolkit   toolkit   = Toolkit.getDefaultToolkit();
        final Clipboard clipboard = toolkit.getSystemClipboard();
        final Image     origImage = new Robot().createScreenCapture( new Rectangle( toolkit.getScreenSize() ) );

        if( !clipboard.isDataFlavorAvailable( DataFlavor.imageFlavor )
            || clipboard.getData( DataFlavor.imageFlavor ) == null ) {
            clipboard.setContents( new ImageSelection( origImage ), null );
        }

        Image clipImage1 = (Image)clipboard.getData( DataFlavor.imageFlavor );
        Image clipImage2 = (Image)clipboard.getData( DataFlavor.imageFlavor );

        System.out.println(origImage.hashCode());
        System.out.println(clipImage1.hashCode());
        System.out.println(clipImage2.hashCode());
        System.out.println(clipImage1.equals( clipImage2 ));


    }

    public static class ImageSelection implements Transferable {
        private Image image;
        public ImageSelection(Image image) {
            this.image = image;
        }
        @Override
        public DataFlavor[] getTransferDataFlavors() {
            return new DataFlavor[]{DataFlavor.imageFlavor};
        }
        @Override
        public boolean isDataFlavorSupported(DataFlavor flavor) {
            return DataFlavor.imageFlavor.equals(flavor);
        }
        @Override
        public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
            if (!DataFlavor.imageFlavor.equals(flavor)) {
                throw new UnsupportedFlavorException(flavor);
            }
            return image;
        }
    }    
}
  • 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-25T03:15:44+00:00Added an answer on May 25, 2026 at 3:15 am

    Q1: The object references were the same in the first case.

    Q2: here is a way to check the data is equal in the screen shots:

      //createScreenCapture() returns BufferedImage which is more useful for what you are doing.
    
      static boolean bufferedImageEquals( BufferedImage b1, BufferedImage b2 ) {
        if ( b1 == b2 ) {return true;} // true if both are null
        if ( b1 == null || b2 == null ) { return false; }
        if ( b1.getWidth() != b2.getWidth() ) { return false; }
        if ( b1.getHeight() != b2.getHeight() ) { return false; }
        for ( int i = 0; i < b1.getWidth(); i++) {
         for ( int j = 0; j < b1.getHeight(); j++ ) {
           if ( b1.getRGB(i,j) != b2.getRGB(i,j) ) { 
               return false;
           }
          }
        }
        return true;
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not sure what the problem is but I keep receiving this error
I'm not sure how to describe this problem, so I think an example is
I'm not sure if this a settings problem or an HTML problem, but on
Big problem. I'm not sure what it was that I did, but it seems
Uhm I'm not sure if anyone has encountered this problem a brief description is
Not sure how to ask a followup on SO, but this is in reference
Not sure what exactly is going on here, but seems like in .NET 1.1
Not sure if the title is quite right for the question but I can't
Not sure if anyone listened to Hanselminutes episodes 134 and 135, but at the
I'm really interested in speech-to-text algorithms, but I'm not sure where to start studying

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.