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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:49:18+00:00 2026-05-30T15:49:18+00:00

I am using an Applet to save image from clipboard. The image is saved

  • 0

I am using an Applet to save image from clipboard. The image is saved but something happened with its format. It is darken and lost colors.

here’s how I am doing it:

AccessController.doPrivileged(new PrivilegedAction() {
    public Object run() {

        try {
            //create clipboard object
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            //Get data from clipboard and assign it to an image.
            //clipboard.getData() returns an object, so we need to cast it to a BufferdImage.
            BufferedImage image = (BufferedImage) clipboard.getData(DataFlavor.imageFlavor);
            //file that we'll save to disk.
            File file = new File("/tmp/clipboard.jpg");
            //class to write image to disk.  You specify the image to be saved, its type,
            // and then the file in which to write the image data.
            ImageIO.write(image, "jpg", file);
            //getData throws this.
        } catch (UnsupportedFlavorException ufe) {
            ufe.printStackTrace();
            return "Não tem imagem na área de transferência";
        } catch (Exception ioe){
            ioe.printStackTrace();
        }
        return null;
    }
}

);

I read that Mac uses a different image format but I did not find how to convert it to a format I could save. I imagined that java should have taken care of that.

So, how can I convert the image from clipboard to jpg?

PS. I tried using png instead of jpg, got a worse result: black 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-30T15:49:20+00:00Added an answer on May 30, 2026 at 3:49 pm

    To solve the issue on Mac, I used the solution proposed on The nightmares of getting images from the Mac OS X clipboard using Java.

    I pass the retrieved BufferedImage to method that redraws it to new BufferedImage, returning a valid image. Here follows the code from that page:

    public static BufferedImage getBufferedImage(Image img) {
            if (img == null) return null;
            int w = img.getWidth(null);
            int h = img.getHeight(null);
            // draw original image to thumbnail image object and
            // scale it to the new size on-the-fly
            BufferedImage bufimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2 = bufimg.createGraphics();
            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            g2.drawImage(img, 0, 0, w, h, null);
            g2.dispose();
            return bufimg;
        }
    

    And how I use it:

    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    //Get data from clipboard and assign it to an image.
    //clipboard.getData() returns an object, so we need to cast it to a BufferdImage.
    BufferedImage image = (BufferedImage) clipboard.getData(DataFlavor.imageFlavor);
    
    if (isMac()) {
        image = getBufferedImage(image);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created an audio Player using java applet but i'm stuck at trying to
Using the iPhone SDK, I'm having the user select images from the image picker.
We have a Java Applet built using AWT. This applet lets you select pictures
I'm working on a project where we're using a Java applet for part of
I'm using firefox3 to run a Java Applet (on Linux). normally, when the JVM
I'm using the Java Deployment Toolkit to deploy a java applet in an iframe.
I am using IText library to facilitate pdf export in an applet. During the
I have an applet that communicates with a servlet using Http (Not sockets). Currently,
i am using apple's sample URLCache ,but when i mention url, it loads data
I am using the following script http://stuporglue.org/recieve-e-mail-and-save-attachments-with-a-php-script/ to handle my emails that get sent

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.