Paste Image to System Clipboard

Hello all...I can't paste an Image to the system clipboard and was wondering if you could help me. Noticed there was some help on this topic with JDK 1.4.1, however I'm using JDK 1.3.1.
I following code was copied from Sun at http://developer.java.sun.com/developer/Books/GJ21AWT/ch20.pdf
but I cant get it to work.
<code>
//implement the class like this
ImageSelection is = new ImageSelection(Constants.DRAWINGSLATE.currentImage.pBitmap[dList.ptr].getImage());
toolkit.getSystemClipboard().setContents(is, null);
class ImageSelection implements ClipboardOwner, Transferable
public static DataFlavor ImageFlavor;
public static DataFlavor ImageArrayFlavor;
private DataFlavor[] flavors = {ImageFlavor, ImageArrayFlavor};
private java.awt.Image image;
private int width, height;
static
try
ImageFlavor = new DataFlavor(Class.forName("java.awt.Image"),"AWT Image");
ImageArrayFlavor = new DataFlavor("image/gif", "GIF Image");
catch(Exception e)
public ImageSelection(Image image)
this.image = image;
public ImageSelection(Image image, int width, int height)
this.image = image;
this.width = width;
this.height = height;
public synchronized DataFlavor[] getTransferDataFlavors()
return flavors;
public boolean isDataFlavorSupported(DataFlavor flavor)
return flavor.equals(ImageFlavor) || flavor.equals(ImageArrayFlavor);
public synchronized Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException
if (flavor.equals(ImageFlavor))
return image;
if (flavor.equals(ImageArrayFlavor))
return imageToArray();
else
throw new UnsupportedFlavorException(flavor);
public void lostOwnership(Clipboard c, Transferable t)
private int[] imageToArray()
int[] pixels = new int[width*height];
PixelGrabber pg = new PixelGrabber(image, 0, 0, width, height, pixels, 0 , width);
try
pg.grabPixels();
catch(InterruptedException e)
e.printStackTrace();
return pixels;
</code>
I get this exception
Couldn't write data flavor java.awt.datatransfer.DataFlavor[representationclass=java.awt.Image;mimetype=application/x-java-serialized-object] to clipboard:
java.io.IOException: Transferable's flavor data is of unexpected class com.apple.mrj.internal.awt.graphics.VImage
Thanks for any help.

I was trying to use ur code with slight modification
import java.awt.*;
import java.awt.datatransfer.*;
import java.io.*;
import java.util.*;
public class Test {
public static void main (String[] parameters) {
          new Test ().test ();
private void test () {
Toolkit.getDefaultToolkit().getSystemClipboard ().setContents (          new mageTransferable ("test.jpg"),
     new ClipboardOwner () {
     public void lostOwnership (                                             Clipboard clipboard,
                         Transferable contents) {}
private class ImageTransferable implements Transferable {
private String fileName;
public ImageTransferable (String fileName) {
System.out.println(" Checking for the File now");
if (! new File(fileName).exists ()) {
throw new IllegalArgumentException ("Can't find image");
System.out.println(" got the file");
this.fileName = fileName;
System.out.println(" returning from constructor");
public Object getTransferData (DataFlavor flavor) throws UnsupportedFlavorException {
System.out.println("trying to get the data to be transfered");
if (! isDataFlavorSupported (flavor)) {
throw new UnsupportedFlavorException (flavor);
System.out.println("This is a supported flavor");
return (Image)Toolkit.getDefaultToolkit().createImage (fileName);
//               System.out.println(
public boolean isDataFlavorSupported (DataFlavor flavor) {
System.out.println("trying to check whether the flavour is supported one");
DataFlavor[] df= this.getTransferDataFlavors();
System.out.println(" data flavors " + df);
boolean result = in(flavor, df);
return result;
public DataFlavor[] getTransferDataFlavors () {
//     "image/x-java-image; class=java.awt.Image"
DataFlavor df=null;
System.out.println("trying to get the data flavours");
df =new DataFlavor("application/x-java-serialized-object; class=java.awt.Image","Image");
//new DataFlavor("image/x-java-image;class=java.awt.Image","Image");
System.out.println(" Just going to return & DF found was"+ df);
DataFlavor[] df2 = new DataFlavor[]{df,DataFlavor.plainTextFlavor,DataFlavor.stringFlavor,DataFlavor.javaFileListFlavor };
System.out.println(df2.length);
System.out.println(df2[0]);
return df2;
private boolean in (DataFlavor flavor, DataFlavor[] flavors) {
System.out.println("Im in in");
int f = 0;
while ((f < flavors.length) && ! flavor.equals (flavors[f])) {
     f ++;
     System.out.println("Im in in's loop");
return f < flavors.length;
But this throws the following exception:
Exception in thread "main" java.lang.ClassCastException: sun.awt.windows.WImage
at sun.awt.windows.WDataTransferer.translateTransferable(WDataTransferer
.java:346)
at sun.awt.DataTransferer.translateTransferable(DataTransferer.java:245)
at sun.awt.windows.WClipboard.setContents(WClipboard.java:69)
at Test.test(Test.java:13)
at Test.main(Test.java:8)
Is the dataflavour purely dependent on OS. What can be done to overcome this problem

Similar Messages

  • Pasting Image  from Mac clipboard to Java Based Application.

    Hi,
    I am working on "iMac 10.2.7". I need to paste an image from other
    application using "Java version 1.4.1". I am trying to retrieve the image
    from the system clipboard after it is copied from some other application. I
    am pasting the code which illustrates my requirement. It works fine on
    windows. But does not work on Mac.
    On Mac it does not cross the supported data flavor check
    (clipData.isDataFlavorSupported(DataFlavor.imageFlavor) where clipData is
    the Transferable object). It seems Mac has some InputStream instead of Image
    in the clipboard when some image is copied. I tried to read that InputStream
    using ImageIO.read(java.io.InputStream). But that is also returning null.
    Thanks
    Santanu
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import java.awt.datatransfer.*;
    import javax.swing.*;
    public class ClipboardTest extends JFrame implements KeyListener{
         JLabel label;
         static Toolkit kit = null;
         static Clipboard clipboard = null;
         public static void main (String arg[]) {
              kit = Toolkit.getDefaultToolkit();
              clipboard = kit.getSystemClipboard();
              JLabel l = new JLabel();
              JButton button = new JButton("Paste from clipboard");
              final ClipboardTest ct = new ClipboardTest(l);
              ct.getContentPane().add(l,BorderLayout.CENTER);
              ct.getContentPane().add(button,BorderLayout.SOUTH);
              ct.setVisible(true);
         button.addActionListener(
              new ActionListener() {
                   public void actionPerformed(ActionEvent ae) {
                        pasteImage(ct.label);
         button.addKeyListener(ct);
         public ClipboardTest (JLabel l) {
              label = l;
         public static void pasteImage(JComponent jComp) {
                   jComp.setTransferHandler(new ImageSelection());
                   TransferHandler handler = jComp.getTransferHandler();
                   Transferable clipData = clipboard.getContents(null);
              if (clipData != null) {
              if (clipData.isDataFlavorSupported(DataFlavor.imageFlavor)) {
                   handler.importData(jComp, clipData);
         //Key listener methods
         public void keyPressed(KeyEvent e) {
         int c = e.getKeyCode();
         if (c == 86) {
              if (e.isControlDown()) {
                   pasteImage(label);
         public void keyReleased(KeyEvent e) {}
         public void keyTyped(KeyEvent e) {}
    class ImageSelection extends TransferHandler implements Transferable {
         /* DataFlavor instance that holds imageflavor value*/
         private static final DataFlavor flavors[] = {DataFlavor.imageFlavor};
         private Image image;
         public boolean importData(JComponent comp, Transferable transferable) {
         try {
         if (transferable.isDataFlavorSupported(flavors[0])) {
         image = (Image)transferable.getTransferData(flavors[0]);
                   if (comp instanceof JLabel) {
                   ((JLabel)comp).setIcon(new ImageIcon(image));
                   comp.repaint();
                   return true;
         } catch (Exception ignored) {
              ignored.printStackTrace();
         return false;
         // Transferable Interface methods
         public Object getTransferData(DataFlavor flavor) {
         if (isDataFlavorSupported(flavor)) {
         return image;
         return null;
         public DataFlavor[] getTransferDataFlavors() {
         return flavors;
         public boolean isDataFlavorSupported(DataFlavor flavor) {
         return flavor.equals(flavors[0]);

    Here are two commercial options:
    JTwain + JSane
    http://asprise.com/product/jtwain/index.php
    Morena
    http://www.gnome.sk/Twain/jtp.html
    Haven't tested them, so don't no how good they are, nor how easy they are to use on multiple platforms.

  • Image to system clipboard running in Thread issue

    In one of my applets I copy an image to the system clipboard. The issue I am having is that if I'm running other threads the "setContents()" method never seems to be allowed to complete or takes a really long time no matter the size of the image. All my threads have "wait" statements and my CPU load is 1%. Has anyone else had this same issue? What is a recommended workaround?

    Do you know that an unsigned applet can't access the clipboard?

  • Copy an image into system clipboard takes too much memory

    Our Swing application copies a java.awt.BufferedImage into the system clipboard. Our image has a size of 1024x768 pixels and a depth of 24 bits per pixel.
    The copy from the image to the system clipboard works, but is very slow and takes too much memory. Before the copy, java.exe uses about 30 MB. After the copy, it uses about 90 MB! However, a 1024x768x3 image should consume only 2,4 MB.
    We did some debugging and it seems the AWT library does several copies of our original image in order to copy it in the system clipboard. I guess that each of these copies takes a lot of memory (probably because of a different format from the original image) and is not immediately garbage collected.
    This is a big issue for our application because the JVM throws an OutOfMemoryError when we try to copy a new image to the system clipboard.
    Here is our code. Do you have any idea? Thanks a lot for your help.
    // Create the image
    BufferedImage image = new BufferedImage(1024, 768, BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D g2 = image.createGraphics();
    drawSomething(g2);
    g2.dispose();
    // Put the image into the system clipboard
    ImageSelection handler = new ImageSelection(image);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(handler, handler);
    * An implementation of Transferable and ClipboardOwner to be used with
    * images.
    public class ImageSelection implements Transferable, ClipboardOwner {
        private static final DataFlavor flavors[] = {DataFlavor.imageFlavor};
        private Image image;
        public ImageSelection(Image imageToCopy) {
            this.image = imageToCopy;
        // Interface ClipboardOwner
        public void lostOwnership(Clipboard clipboard, Transferable transferable) {
            image = null;
        // Interface Transferable
        public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException,
                                                                IOException {
            if (isDataFlavorSupported(flavor)) {
                return image;
            else {
                throw new UnsupportedFlavorException(flavor);
        public DataFlavor[] getTransferDataFlavors() {
            return flavors;
        public boolean isDataFlavorSupported(DataFlavor flavor) {
            return flavor.equals(flavors[0]);
    }

    why dont u use other data structure to store the image , which will take less memory.

  • How to a copy a tif image to system clipboard and paster in MS Word

    import java.awt.image.RenderedImage;
    import java.io.IOException;
    import javax.media.jai.RenderedImageAdapter;
    import util.TIFFFileHelper;
    public class ClipboardSupport implements ClipboardOwner{
         public ClipboardSupport() {
              super();
         public static void main(String[] args) throws IOException {
              ClipboardSupport co = new ClipboardSupport();
              RenderedImage img=co.getTestImage();
              co.copyToClipBoard(img);
         private RenderedImage getTestImage() throws IOException{
              TIFFFileHelper th = new TIFFFileHelper("C:/workspace/AV/src/images/onepageSample.tif");
              th.getPageCountParseFirstPage();
              RenderedImage img = th.getFirstPage();
              return img;
         public void copyToClipBoard(RenderedImage img2){
              Image img=this.getCovertedImage(img2);
              this.copyToClipBoard(img);
         public void copyToClipBoard(Image img){
              Toolkit tkt = Toolkit.getDefaultToolkit();
              Clipboard clipboard = tkt.getSystemClipboard();
              Transferable t = new ImageSelection(img);
              clipboard.setContents(t,this);
         public void lostOwnership(Clipboard clipboard, Transferable contents) {
              System.out.println("ClipboardSupport.lostOwnership() called");
         private Image getCovertedImage(RenderedImage img) {
              RenderedImageAdapter aid = new RenderedImageAdapter(img);
              Image im = aid.getAsBufferedImage();
              return im;
    package util.clipboard;
    import java.awt.Image;
    import java.awt.datatransfer.DataFlavor;
    import java.awt.datatransfer.Transferable;
    import java.awt.datatransfer.UnsupportedFlavorException;
    import java.io.IOException;
    public class ImageSelection implements Transferable {
         private Image img=null;
         DataFlavor dataFlavor = DataFlavor.imageFlavor;
         public ImageSelection(Image img) {
              super();
              this.img=img;
         public DataFlavor[] getTransferDataFlavors() {          
              DataFlavor[] data = new DataFlavor[1];
              data[0]=dataFlavor;
              return data;
         public boolean isDataFlavorSupported(DataFlavor flavor) {          
              if(dataFlavor.equals(flavor)){
                   return true;
              }else{
                   return false;
         public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
              return img;
    }

    done.

  • System clipboard, AWT TextAreas, and JTextAreas

    This code makes a JApplet with a Swing JTextArea and an AWT TextArea. The JTextArea won't accept pasted text that was copied from another application. The AWT TextArea will. Why is this, and how can I get a JTextArea to accept pasted input?
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.util.*;
    public class TextAreaTest extends JApplet {
         Container cp = getContentPane();
         JTextArea TextIn = new JTextArea("You can't paste from the system clipboard into this box.",4,44);
         JScrollPane aScrollPane = new JScrollPane(TextIn);
         TextArea awtTextIn = new TextArea("Pasting into this box does work!",4,44);
         public void init() {
              cp.setLayout(new FlowLayout());
              cp.add(new Label("Copy some text from another program."));
              cp.add(new Label("Click in the upper box and press Shift+Insert."));
              cp.add(new Label("Why is nothing pasted?"));
              cp.add(aScrollPane);
              cp.add(awtTextIn);
    //<applet width="500" height="240" code="TextAreaTest.class"></applet>

    Thanks for checking this and replying. Pasting into the JTextArea from outside doesn't work for me, even when I'm running the applet locally. Even when I run the applet with appletviewer from the command prompt, I still can't paste from the outside into the JTextArea. If I cut from the TextArea or from an outside application and try to paste into the JTextArea, nothing happens. I can't go the other way either: If I cut from the JTextArea and try to paste into the TextArea, nothing happens. The only cutting and pasting that works with the JTextArea is that if I cut from within the JTextArea, I can paste back into the JTextArea.
    I wonder why pasting works for you and not for me. I'm using the latest JDK (1.4.2_03) and JRE on Windows XP. I have the same behavior on a Windows 2000 machine with the 1.4.1 JRE.

  • Pasting images that have been put onto the clipboard by other applications

    I have the following problem. Might be that I am just overlooking something but I haven't found any information or other java programs that would solve this problem.
    I want to access the System Clipboard and retrive images copied onto the System Clipboard by an other application (e.g. paint, irfanView, ... ). Copy and pasting works perfectly with Strings or Images I myself copied to the Clipboard, but as soon as I want to access an image from an other application clipboard.getContents(this) returns null as though the Clipboard was empty. (Where clipboard =getToolkit().getSystemClipboard();)
    I downloaded a couple of other java applications that handle images (e.g. ImageJ) and found out that those also can't paste images from other sources.
    Is there a way to do that? Has anybody found a solution for that or have I really overlooked something, and it's just one of those stupid bugs one never finds by oneself?

    Hi,
    this was exactly my problem. With "Copy and pasting works perfectly with Strings or Images I myself copied to the Clipboard" I mean that I copied the Images and Strings from within a Java Application on to the System Clipboard. It didn't work if the image came from another win32 application. I solved the problem by using JNI, reading the images from the clipboard using C++ and then passing an int[] array to the java application.

  • Paste from System Clipboard

    Hi,
    I've been looking all over on how to copy and paste to/from the system clipboard. I've used the tutorial classes at http://java.sun.com/developer/technicalArticles/releases/data/ explaining new data transfer capabilities in java, and it seems that I can copy and paste to/from a java application but I can't seem to paste images from the system clipboard in applications such as Thunderbird and OpenOffice.
    I'm not sure what the problem or solution is, but if anyone has any ideas that would be great. I was thinking it may be that in the tutorial it is copying the content of a JComponent to the system clipboard but I'm pretty sure that is not it.
    Any help is appreciated.
    thanks

    import java.awt.*;
    import java.awt.datatransfer.*;
    public class ClipboardImage
          *  Retrieve an image from the system clipboard.
          *  @return     the image from the clipboard or null if no image is found
         public static Image read()
              Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents( null );
            try
                if (t != null && t.isDataFlavorSupported(DataFlavor.imageFlavor))
                    Image image = (Image)t.getTransferData(DataFlavor.imageFlavor);
                    return image;
            catch (Exception e) {}
            return null;
          *  Place an image on the system clipboard.
          *  @param  image - the image to be added to the system clipboard
         public static void write(Image image)
            if (image == null)
                throw new IllegalArgumentException ("Image can't be null");
              ImageTransferable transferable = new ImageTransferable( image );
            Toolkit.getDefaultToolkit().getSystemClipboard().setContents(transferable, null);
        static class ImageTransferable implements Transferable
            private Image image;
            public ImageTransferable (Image image)
                this.image = image;
            public Object getTransferData(DataFlavor flavor)
                 throws UnsupportedFlavorException
                if (isDataFlavorSupported(flavor))
                     return image;
                else
                    throw new UnsupportedFlavorException(flavor);
            public boolean isDataFlavorSupported (DataFlavor flavor)
                  return flavor == DataFlavor.imageFlavor;
            public DataFlavor[] getTransferDataFlavors ()
                return new DataFlavor[] { DataFlavor.imageFlavor };
         public static void main(String[] args)
              Image image = Toolkit.getDefaultToolkit ().createImage("???.jpg");
              ClipboardImage.write( image );
              javax.swing.ImageIcon icon = new javax.swing.ImageIcon( ClipboardImage.read() );
              javax.swing.JLabel label = new javax.swing.JLabel( icon );
              javax.swing.JFrame frame = new javax.swing.JFrame();
              frame.setDefaultCloseOperation( javax.swing.JFrame.EXIT_ON_CLOSE );
              frame.getContentPane().add( label );
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible(true);
    }

  • Need to save the image saved in the System Clipboard in using JDK 1.3.1

    Does anyone know how to use JDK 1.3.1 to take an image saved in the System clipboard and save it to a file using the JPG format?
    I know how it is done in JDK 1.4 using the following code. Unfortunately, the same code does not recognize the image in the clipboard in JDK 1.3.1
    I am using jai-1_1_2_01.
    package clipboard;
    import java.awt.datatransfer.Clipboard;
    import java.awt.datatransfer.DataFlavor;
    import java.awt.datatransfer.Transferable;
    import java.awt.image.RenderedImage;
    import java.awt.Toolkit;
    import java.awt.datatransfer.UnsupportedFlavorException;
    import java.io.IOException;
    import java.io.FileOutputStream;
    import java.io.BufferedOutputStream;
    import java.io.File;
    import javax.media.jai.JAI;
    import javax.media.jai.RenderedOp;
    public class clipboard
    {  private File tempFile = null;
    * @param args
    static int BUFFER_SIZE = 65536;
    public static void main(String[] args)
    {  clipboard clip = new clipboard();
    clip.writeImageFromClipboard();
    public void writeImageFromClipboard()
    {  Clipboard            clip = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable transferable = clip.getContents(null);
    RenderedImage img = null;
    FileOutputStream fileOutStr = null;
    BufferedOutputStream bufOutStr = null;
    DataFlavor [] dataFlavors;
    File tempFile;
    int
    byteCount;
    String [] strArr;
    dataFlavors = transferable.getTransferDataFlavors();
    System.out.println("clip=" + clip.getName());
    System.out.println("Transferable=" + transferable);
    for (int i = 0; i < dataFlavors.length; i++)
    {  System.out.println("dataFlavours[" + i + "]=" + dataFlavors.toString());
    if (transferable.isDataFlavorSupported(new DataFlavor("image/x-java-image; class=java.awt.Image", "Image")))
    { try
    { img = (RenderedImage) transferable.getTransferData(new DataFlavor("image/x-java-image; class=java.awt.Image", "Image"));
    if (this.tempFile == null)
    { this.tempFile = File.createTempFile("__TMP_IMG__", ".jpg");
    System.out.println(this.tempFile.getCanonicalPath());
    fileOutStr = new FileOutputStream(this.tempFile);
    bufOutStr = new BufferedOutputStream(fileOutStr);
    // Encode the file as a JPG image.
    JAI.create("encode", img, bufOutStr, "JPEG", null);
    catch (UnsupportedFlavorException e)
    { e.printStackTrace();
    catch (IOException e)
    { e.printStackTrace();
    finally
    { if (bufOutStr != null)
    { try
    { bufOutStr.flush();
    bufOutStr.close();
    catch (IOException e)
    if (fileOutStr != null)
    { try
    { fileOutStr.flush();
    fileOutStr.close();
    catch (IOException e)
    else
    { System.out.println("Not an image!");

    The login  you connected to the server  and run the above statement does not have permissions to operate  on this path "C:\Users\ISLLCdba\Desktop\MAA
    PROFILE PICTURES\"
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Copy & Paste images to forms from the clipboard

    hello,
    Java Plug-in 1.6.0_33
    Using JRE version 1.6.0_33-b05 Java HotSpot(TM) Client VM
    Forms Applet version is 11.1.2.0
    Windows 7 64bitForms has successfully done the drag&drop,save image file images to javabeans then save & retrieve it from database.
    Laf project has an example of table-block copy/paste from/to the clipboard feature. You can populate a table-block with the content of the clipboard (Excel, Word,...) and also send to the clipboard with the content of a table-block.
    But a how about the copy & paste images to forms?
    It is posible?Any one tried this one?
    Charles
    Edited by: ck on Aug 12, 2012 3:09 AM

    bump...

  • Copy and paste a image to the clipboard

    Hi,
    Is there anybody who knows how to copy and paste an image to the clipboard in jdk 1.3.0.
    I want make a image copy of my app like this (Panel):
    Image image = (Image)this.createImage(this.getWidth(), this.getHeight());
    Graphics g = image.getGraphics();
    this.paint(g);
    BufferedImage bufImage = (BufferedImage)image;
    Now i will send this bufImage or the image to the clipboard.
    How will it works?
    Thanks a lot.

    Hi,
    I m having similar type of problem but with JPanel not with image. i m able to copy paste a JPanel using same clipboard but i want some more operations like after zoomin my JPanel , i want that now if i copy the image of Jpanel it should be the copy of original size of JPanel not the zoomed one but in my application it is showing the blank picture
    for zoom fit size of JPanel its working ok.
    please advice me what should i do

  • I want to paste image in a from a clipboard into any canvas

    i want to paste image in a from a clipboard into any canvas

    Yeah, well I want to win the lottery :=)
    You should check out the stuff in java.awt.datatransfer That package has info on how to do this sort of thing, as well as ClipBoard objects + the like.

  • Sending an image to the system clipboard

    I've been trying to figure out how I can send an image to the system clipboard. At this state I'm beginning to think it's just not possible. This is the case:
    I've got an applet running in a browser which creates a new window. I now want to copy the contents of this window to the system clipboard. So far I can only transfer text to the clipboard, but what I need is to copy a screenshot of the new window to the system clipboard.
    Does anybody know how this can be done with Java or any kind of scripting language?

    Since I already found the answer I rewarded 2 people for there help. This is the answer I found. Some code was found on the JDC Forum, but I can't remember who posted it or where I found it. So sorry that I can't give him credit...
    Using JDK 1.4 the code could look like this:
    -> This is how the policy file should look like:
    grant
    { permission java.awt.AWTPermission "accessClipboard";
    permission java.awt.AWTPermission "createRobot";
    permission java.awt.AWTPermission "readDisplayPixels";
    -> This is the code for the applet:
    import java.awt.*;
    public class ClipboardTest extends java.applet.Applet {
    public void init() {
    initComponents();
    initialiseer();
    private void initComponents() {
    setLayout(new java.awt.BorderLayout());
    public void initialiseer() {
         // Here I create the actual frame that I can send to the clipboard
    MySystemClipboard cb = new MySystemClipboard();
    cb.setBounds(200,200,200,200);
    cb.setVisible(true);
    -> And here is the code for MySystemClipboard:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.awt.datatransfer.*;
    public class MySystemClipboard extends Frame implements ActionListener,
    ClipboardOwner
    private Button myButton;
    private Clipboard myClipboard;
    private PrettyPicture myPicture;
    public MySystemClipboard()
    add(myButton = new Button("Clip"), BorderLayout.SOUTH);
    add(myPicture = new PrettyPicture(), BorderLayout.CENTER);
    myButton.addActionListener(this);
    myClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    public void actionPerformed(ActionEvent anEvent)
    try
    ClipImage ci = new ClipImage(new Robot().createScreenCapture(getBounds()));
    myClipboard.setContents(ci, this);
    catch (AWTException ae){}
    public void lostOwnership(Clipboard clipboard, Transferable contents)
    private class ClipImage implements Transferable
    private DataFlavor[] myFlavors;
    private BufferedImage myImage;
    public ClipImage(BufferedImage theImage)
    myFlavors = new DataFlavor[]{DataFlavor.imageFlavor};
    myImage = theImage;
    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException
    if (flavor != DataFlavor.imageFlavor)
    throw new UnsupportedFlavorException(flavor);
    return myImage;
    public DataFlavor[] getTransferDataFlavors()
    return myFlavors;
    public boolean isDataFlavorSupported(DataFlavor flavor)
    return (flavor == DataFlavor.imageFlavor);
    private class PrettyPicture extends Panel
    public PrettyPicture()
    setBackground(Color.gray);
    add(new Button("Button1"), BorderLayout.NORTH);
    add(new Button("Button2"), BorderLayout.CENTER);
    add(new Button("Button3"), BorderLayout.SOUTH);
    Hope this can help some other people

  • Copy/Paste Image from Clipboard - still no support for transparency?

    I just tried to load an Image from the Clipboard by using DataFlavor.imageFlavor. Everything works well if the clipboard-image doesn´t use any transparency. When loading an image with alpha-channel (png or gif), the transparency occurs as black pixels. Here is the code snippet:
    Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();;
    Transferable t = clip.getContents(null);
    BufferedImage img = (BufferedImage) t.getTransferData(DataFlavor.imageFlavor);img.getType allways returns TYPE_INT_RGB, even if the image contains alpha-data.
    According to this Bug-Report
    [http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4720930]
    this should have bin fixed in 1.4.2, if i´m not wrong?
    Can anyone confirm this problem, and is there any workaround? The one described in the bug-report doesn´t work for me, since clipboard-images in my case don´t match DataFlavor.javaFileListFlavor.

    The best is to try it yourself I guess.
    Go to Github and try pasting an image into the compose editor.
    The editor definitely supports image pastings. They work directly in Chrome(ium).
    Thus I am wondering why Firefox does not support direct pasting from clipboard into the editor.
    See the attached screenshot regarding the editor I am talking about.

  • ActionScript 3 paste image from clipboard

    Is it possible to paste image from clipboard using ActionScript 3 and Flash Player 11?
    Need web solution only, not AIR.
    Use case:
    - User opens image some in some native image editor.
    - Selects part of image and clicks Ctrl+C (Command+C on Mac). Now part of image is in clipboard.
    - User open web application that is running in Flash Player
    - User inputs image by clicking Ctrl+V (Command+V on Mac) or using context Menu->Paste.
    I browsed the docs for Clipboard at: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/desktop/Clipboard .html
    The only format that seems reasonable would be Clipboard.getData(BITMAP_FORMAT) on paste events. This seems to be supported by AIR only.
    Are there any ways to implement the given use case with Flash Player?
    Thanks!
    P.S.: There is some support of paste events in HTML in Chrome and Firefox, but Internet Explorer 10 and Apple Saffari 6 seems still have issues with pure-HTML approach.
    Cheers,
    Ignat.

    This seems to be supported by AIR only.
    What gives you the impression?
    AIR-only functions are marked with a fancy AIR logo
    (like the first one in this list: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/images/sprite-index.png )
    and getData doesn`t have it, so it should work without problems in the "normal" Flash Player if you follow the recepy:
    Note for Flash Player applications: In Flash Player 10, a paste operation from the clipboard first requires a user event (such as a keyboard shortcut for the Paste command or a mouse click on the Paste command in a context menu). Clipboard.getData() will return the contents of the clipboard only if the InteractiveObject has received and is acting on a paste event. Calling Clipboard.getData() under any other circumstances will be unsuccessful.

Maybe you are looking for

  • Calling Web Service from PL/SQL in 9.2.0.4

    We're having some problems getting the "Calling Web Services Sample from PL/SQL" sample working with our 9.2.0.4 database. After downloading the sample from http://www.oracle.com/technology/tech/webservices/htdocs/samples/dbwebservice/DBWebServices_P

  • DB13 - Job Calendar

    How Do, I am trying to delete some on-line DB backups in DB13. When I highlight a particular day and press the delete icon the message 'Actions have been deleted' appears at the bottom of the screen. Which suggests the job has been deleted. However,

  • Loading the wrong messages properties files

    Hi I'm using myfaces implementation version 1.1.3 with JBoss-4.0.3 (Tomcat 5.5). I have a single .ear file, containing several .war and .jar files. My main application is foo.jar, and I have several web archives, say foo_a.war and foo_b.war for examp

  • Session sharing or authentication filter ???

    here is the situation user comes on main web site. after he logs into system, he sees our new link.(say sample1.jsp) which should be protected and which is hosted on different application server then main. so how i protect sample1.jsp behind login. l

  • Purple Camera Lens Crack -- Covered?

    I'm not sure if this is a question anyone can help with, but about a month ago I noticed a mark showing up in my iphone photos. At first I thought it was a dead pixel, but I realized when I zoomed in that it was purple which can only mean its a micro