Copying Image to clipboard

I would like to copy graphics (e.g. plot or table) in the application to the SystemClipboard. The goal is to be able to transfer this image to the other application.
It is rathewr simple to copy text, however it is not clear how to copy graphics.
Anybody has experience?
Code snippet would be helpful
Thank you.
Leo

If you have access to JDK 1.4, you can use java.awt.Robot quite simply with the predefined imageFlavor. Before that, I don't know how to get the system to recognize the Image flavor really...anyone?
Here is an example how with 1.4:
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("Klipp"), 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.blue);
            add(new Button("Moo"), BorderLayout.NORTH);
            add(new Button("Boo"), BorderLayout.CENTER);
            add(new Button("Roo"), BorderLayout.SOUTH);
    public static void main(String[] args)
        MySystemClipboard cb = new MySystemClipboard();
        cb.setBounds(200,200,200,200);
        cb.setVisible(true);
}This works for me with JDK1.4 in Windows NT, using Word to verify the clipboard contents (pasting in pictures). This does not work in previous versions, since DataFlavor.imageFlavor didn't exist then. I don't know of any equivalent substtitute.
You can easily change the bounds of the picture to catch, as well as the actual contents of it
HTH,
Fredrik

Similar Messages

  • Copy image from clipboard

    hi
    Is there any way to find out about type of image that you are coping from clipboard. Because i receive only this type image/x-java-image. I need to know if image is jpg or png.

    read the OP, OK then. "image/x-java-image", not application/x-java-file-list.
    the question was "what type of image was
    copied to the clipboard". if it was pixel/raw data
    then whether or not it was jpg or png is what's
    irrelavent. That is what I said in my first post. "image/x-java-image" is what Java return when you copy a Image (print screen, open Paint select, copy etc).
    When you copy a File it returns a List of Files.
    i felt it was obvious that this was a
    file (which is still an image) and not pixel buffer
    data.It sounds to me like the OP has copied an image from an image program (or hit print screen). At which point it is a raw pixel buffer.

  • Copy Image to Clipboard - possible in jdk1.3?

    The subject line says it all - is it possible to transfer images to the system clipboard using jdk1.3?
    I know that jdk1.4 has DataFlavor.imageFlavor, but is there any way around this in jdk1.3?

    I'm not that expert in Copy/Paste, but I suppose you could make an Image class which implements Transferable and try with flavor "localJVMMimeType" (or something like that, see the tutorial), and the class you want to use.
    Greetings,
    Silkje.

  • Safari cant copy images

    I went to amazon.com and tried to copy some of the images for the Zire 72 and paste it into an email message, but everytime it copied the image address. I set it to copy the image, and not the image address, but when I pasted into the email body, I saw the address. And no I do not currently and never plan to use Apple mail.
    I had the same problem with FireFox(which cant copy images to the clipboard anyways). To fix the problem I had to use classic Internet explorer. What a hassle.
    John

    Hi John!
    I'm not sure which images you are trying to C & P from Amazon.com, but, using Safari, I was able to copy the image found HERE, and paste it into an AOL eMail document. It was then successfully sent, and when opened, the image appeared in the body of the mail.
    Maybe I'm not quite understanding what you're trying to do.
    Position the cursor on the image.
    Press the "Control" key and hold the mouse down.
    Select "Copy Image to Clipboard".
    Open a new AOL eMail document.
    Click in the message area of the document.
    Select "Paste" from the "Edit" menu, or "Command Key + V Key.
    Your will be presented with a resizing option. Click Yes or No.
    Address your eMail and send!
    Good Luck!
    ali b

  • Copy a Dicom Image to Clipboard

    hello,
    Iam trying to copy a DICOM image to clipboard using java swing.
    But at the time of copy it shows the following Exception.
    com.sun.medialib.codec.png.PNGException:
    codecLib: image palette error. [PLTE]
    at com.sun.medialib.codec.png.Encoder.setPalette(Encoder.java:187)
    at com.sun.media.imageioimpl.plugins.png.CLibPNGMetadata.writeMetadata(CLibPNGMetadata.java:2616)
    at com.sun.media.imageioimpl.plugins.png.CLibPNGImageWriter.write(CLibPNGImageWriter.java:198)
    Iam using the code part to copy the image is:------
    public void setClipboard() {
    m_bufImage = m_origImage = m_currBean.getImage();
    if (m_bufImage != null) {
    ImageSelection imgSel = new ImageSelection(m_bufImage);
    try{
    Clipboard clipboard = Toolkit.getDefaultToolkit ().getSystemClipboard();
    clipboard.setContents(imgSel,null);
    }catch(Exception e){
    e.printStackTrace();
    If anybody is familier with this error please send me a solution to solve this problem.
    thanks in advance
    suryasri

    Hi,
    try to read this SUN article.
    http://developer.java.sun.com/developer/technicalArticles/releases/data/
    Hope this help you.
    Bye
    Ste

  • Adobe Reader 9 Mac - cannot copy images

    I upgraded to Reader 9, and another person in our office is using 8 with the same problem. We can no longer copy images out of a PDF - when we try to paste an image that appeared to be copied we only get a gray box. We've tried many ways including pasting directly into Word or Excel, choosing 'New from Clipboard' in Photoshop Elements, creating a blank Photoshop file and pasting, etc. This has works perfectly in Acrobat 5.0 and in Reader 7.0.5 (which I have gone back to using - I'm sure glad I waited before removing it from my system!).
    Any thoughts?

    (Gary_Roger) wrote:
     I was wrong on both counts. With the help of the local Apple store, I found a solution. First, I Moved to Trash all adobe related files/folders from /Users/*myaccount*/Library/Cache and /Users/*myaccount*/Library/Preferences. When I started "Adobe Reader 9", I at least got the license agreement but again it failed with an "internal error". I then moved the /Users/*myaccount*/Library/Application Support/Adobe folder to my desktop. I was then able to start "Adobe Reader 9" successfully.
    I was having the "Internal Error" message on all my repeated installs of Reader in Mac OS 10.6 ("Snow Leopard") and this fixed it for me. The only thing I did different, was after the app finally launched without an error, I dragged all the non-Acrobat Reader folders inside of /Users/*myaccount*/Library/Application Support/Adobe back to the folder. I then re-launched Reader just to check and all was fine.
    Thanks! This fixed my Adobe Reader on Snow Leopard problem.

  • Paste image from clipboard works in Chrome but not in Firefox

    Hi there,
    I would like to know a bit more about the technical reasons why image pasting from clipboard works on Chrome but not Firefox.
    Steps to reproduce:
    1. Open the text editor on github.com, e.g. by commenting on an issue
    2. Copy an image to clipboard
    3. Put the mouse cursor into the text editor area
    4. Use CTRL+V to paste the image into the text editor
    On Chrome, the image is pasted and automatically uploaded on Github. On Firefox nothing happens.
    Can someone please shed light on this lacking feature?
    I would so much love to see support for this on Firefox as it is a very convenient functionality.
    Thank you!

    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.

  • How do i copy images from the web?

    How do I copy images on the web for use in a powerpoint presentation?

    Drag them to the desktop or control-click them and choose to copy them to the clipboard.
    (61484)

  • Copy Image command is broken.

    I have just completed an upgrade to Mac OSX 10.3.9, the security update and the accompanying update to Safari to 1.3.2.
    And my wife pointed this out to me... the Contol-Click "Copy Image" function is not broken, as it does not copy the image to the clipboard, but rather the URL of the image or the LINK is what gets pasted into other app.
    According to Safari Help, that is NOT the correct fucntionality.
    To save an image, drag it from the webpage to the desktop or a document in another application. You can also hold down the Control key and click the image, then choose Save Image To to save it as a file or Copy Image to paste it in another document.
    The cntl-Click options pop-up now read:
    "Save Image to the Desktop
    Save Image"
    This is definitely a Safari glitch, as Drag and Drop still works to move the image, not the URL or Link. I was also able to do a proper "Save As.. " with the ablility to select the destination, this in now gone as well.
    Bug, or new (crappy) "feature?"
    Anyone run into this, or have a fix to restore the functionality?
    Kurt Griffith
    Nanuet, NY
    G4 Quicksilver 733 1GB Ram   Mac OS X (10.3.9)  

    Ahhh... that is helpful. Gets me halfway there.
    Possibly the issue is that some coding changes in either Safari or OS X have the function work correctly in 10.4.x but are glitchy in 10.3.9... ?
    The same problem persists in Safari 1.3.2 (on our iBook) in 1.3.9
    Ahhh.. interesting (not all apps have "Paste Special"...) Works in MS Word X, but not Appleworks. Preview "New From Clipboard" works as advertised.
    Problem could just as easily be with Appleworks somewhat outdated code? 6.2.4 dates to 2002.
    Thank you Tom, for giving me some avenues to investigate.

  • I'd like to save to file/database image from clipboard

    Hi, I've got following problem.
    In my swing application I would like to pase image from clipboard (f.ex. copied from msword). I use following code to do that:
    TransferHandler handler=jLabel.getTransferHandler();
    handler.importData(jLabel,clipData);
    Then I want to save image to database.
    I know it should look like this:
    ImageIO.write(RenderedImage im, String formatName, OutputStream output);
    But how to transform image from clipboard or graphics from jLabel1.getGraphics into RenderedImage ???
    thanx in advance !

    Starting with the original image I adjusted the levels (Image>Adjustments>Levels (Ctrl L) to the following settings:
    Then using the marquee tool I selected the areas not in use and filled with white:
    Till you get something like this:
    Then I used the brush tool to fill the other bits of the lines in white using these settings:
    Once you are happy with the result with a white background go to the Blending Options on your layer:
    and set the blend as below and press ok:
    This will make your layer look like its got a transparent background, then create a new transparent layer and place underneath:
    When you have done this combine the 2 layer by selecting both and then right click and merge layers:
    After these steps save as a .psd file then you can copy anything you need from this file.
    I hope this all makes sense and you get the result you want. Like I said fiddly! :-)
    End result:

  • How to copy image of a window by window title programatically?

    I would like to be able to programmatically copy the image of a window
    that is one of several that are open by using the window title. 
    Once copied to the clipboard I would like to paste the image to a
    file.  Suggestions?  Some less elegant options such as just
    copying the active window would be considered.
    Thanks,
    Dennis U

    A couple of links which can help you.
    Here you will find a collection of windows tools, which will also allow you to bring a window to the front by title.
    Here you will find a VI which shows you how to "click" alt+printscreen to get the image into the clipboard.
    Using the scripting (I think you have to register with LAVA to read that specific board) abilities you can use the GetClipboardImage method to get the image in LV picture format and save it to a file.
    I will leave it up to you to put it all together.
    Try to take over the world!

  • Copy JPanel onto clipboard

    Hi, I have spent the entire afternoon googling and searching these forums for some ideas and clues as how to go about this, but with no luck. So I have decided to just ask to how it is done.
    I have a JFrame applicationWindow that contains 2 JPanels: InputPanel and outputPanel. Both JPanels are created in independant classes as I am trying to achieve a MVC architecture. What I would like to do is have a button in the application window that will copy the output Panel into the system clipboard. The outputPanel conatains only a painComponent() method that draws some lines onto the outputPanel itself.
    Could somebody please explain to me how this can be done? I have searched for some examples but nothing that explains it well has come up.
    i think i need to use:
              if(arg0.getSource().equals(copyItem))
                 Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
                 cb.setContents(?,?);  
              }But I am unsure as to what goes inside the brackets of the setContents(). I don't understand the Transferable stuff either...
    Sorry if I haven't explained my situation too well, any questions just ask.
    Thanks

    I've experienced problems copying images to the system clipboard. it would copy however when i got in other software the clipboard would not be compatible because it was java only. if you only need to copy and paste within your app, i suggest you forget those Clipboard classes and just had menus with shortcuts that copy your image/panel/whatever into another object, or pastes it.

  • How to copy images from another MC in reversed order??

    Hi everyone,
    I'm new to AS3 and have been fighting and searching for a solution to this problem for a week now, and I'm VERY close!
    I crated a MC holding of a series of images (about 50) and I jump around in it using plenty AS3 scripts (most of which I don't fully understand yet, but I'm working on that to! )
    I had to find a way to "rewind" (= play backwards) the MC. Since there is a stop(); command in almost every frame, prevFrame does not work and if I put that in a loop, it goes WAY to fast (but worked).. So I could think of only one way...
    Create a new (reverserd) MC with the same image sequence ald reverse it manually and play that one.
    This all works fine (very proud of it ).
    Now my question:
    To get this to work for multiple image sequences, I have to load all images twice (once in MC_1 and again in MC_2 and select them and reverse them).
    Not a big one, unless you want to create MANY of those SWF's...
    Is it possible to load the 50 images of the first MC in reverse into the second MC dynamically? JUST the images, noting else.
    extra info: the MC_2 is already in the lib(empty) and placed on the stage.
    something like:
    var pointer:Number=1;
    for (var:i:Number=50;i>=0;i--) {
    get MC_1.picure(var);
    put it in MC_2.frame(pointer);
    pointer = pointer + 1;
    All help is welcome and please take into account that I have little experience and copy most of my scripting from people like you
    T.I.A.
    Melluw

    I tried your advice (thanks for that)
    The event I already have is the mouse leave
    I //-d out the part I removed (what did work)
    The code I ended up with is:
    function Start() {
    stage.addEventListener(Event.MOUSE_LEAVE, cursorHide);
    function cursorHide(evt:Event):void {
    var currFrame = MC_1.currentFrame;
    if (CCW == true) {  //it is true in this case
      movStart = (50 - currFrame);
    else {
      movStart = currFrame;
    if (movStart>25) {
      MC_1.prevFrame();
    // removed swapChildren(MC_1, MC_2); // This is the part I removed
    // removed MC_2.gotoAndPlay(movStart);
    else {
      MC_1.gotoAndPlay (movStart);
    And if I leave the stage on the part where movStart is indeed >25
    Nothing happens,
    So I guess this is not what you meant
    Subject: Action Script 3 how to copy images from another MC in reversed order??
    I cannot direct you in the loading of the images approach, it will be too complicated, and will probably not work anyways... when you move away from a frame that has dynamic content, you lose the content.  So basically, there is nothing practical in taking that approach.
    I do niot understand what the problem will be with the enterFrame/prevFrame approach. If everything you can do with the mouse is already used (which I doubt) by the first mc, then there is nothing else you can do with this file.  You probably just need to rethink your control scheme.  You should search Google for "AS3 slideshow tutorial", and to lighten up your design, add "XML" in that search.
    >

  • I can`t copy image from the web sites to Microsoft Word, since I update firefox ! Why ? How I can fix it ???

    <blockquote>Locking duplicate thread.<br>
    Please continue here: [[/questions/939085]]</blockquote>
    I am tryin to copy image form ZABBIX to Word document. Everything was fine before update and now I am having a problem

    More generally, when you have a problem with one particular site, a good "first thing to try" is clearing your Firefox cache and deleting your saved cookies for the site.
    (1) Bypass Firefox's Cache
    Use Ctrl+Shift+r to reload the page fresh from the server.
    (You also can clear Firefox's cache completely using:
    orange Firefox button ''or'' Tools menu > Options > Advanced
    On the Network mini-tab > Cached Web Content : "Clear Now")
    (2) Remove the site's cookies (save any pending work first) using either of these:
    While viewing a page on the site:
    * right-click and choose View Page Info > Security > "View Cookies"
    * Alt+t (open the classic Tools menu) > Page Info > Security > "View Cookies"
    Then try reloading the page. Does that help?

  • Signed Applet JTextField copy to system clipboard

    Hi all,
    We have a signed and deployed our JAR file that contains our applet following the instructions listed at:
    http://java.sun.com/products/plugin/1.3/docs/rsa_signing.html
    We used Thwate as our CA. All seemed good.
    However any JTextFields that are in our applet cannot access the system clip board. Looking at the source for JTextComponent it should have access to the system clipboard if the securitymanager allows it.
    The strange thing is that if I call getToolkit().getSystemClipboard() from our applets I can access the clipboard and copy to the system clipboard. Even the code in JTextComponent that checks for system clipboard access (canAccessSystemClipboard) works fine when pasted into the applet.
    Why cant a JTextField copy to the clipboard? Has anyone else come across this?

    Juste an idea.... Is your JTextField belonging to the javax.swing.... packages ?
    Or did you compile using some com.ms , ibm.... sun... package ? This could lead to some different implementations.

Maybe you are looking for

  • Select in HTML/ PL/SQL

    Hello Everyone, I'm not sure that is this the correct place to post it, point me in right direction. I have a select box which gets populated from the table, and have so that user can multiselect.... I have this in the form and want to know when that

  • Where should I put the sevlet

    I just started to work with Tomcat and I compiled the helloWorld sevlet. It's said from a book that the sevlet should be placed in serlver_root/webapps/ROOT/WEB-INF/classes, however there isn't a "classes" folder in my WEB-INF folder. So I put the he

  • IP address constantly changes requiring adding new port to enable wireless printing

    I have a HP Photosmart C7280 printer setup with wireless option.  My home network uses a wireless Linksys router.  My problem is that the IP address constantly changes, so when trying to print from the desktop in the other room, I have to go through

  • Cross site scripting errors in RoboHelp 8.0

    We are using Robohelp 8.02, generating webhelp for a web application. Development just started to use Fortify to identify security vulnerabilities. The Fortify software found 17 Robohelp htm files with cross-site scripting security holes. We are NOT

  • Cursor - Suggestions for Dynamic select statements

    Hey, Am trying to define a cursor like this - cursor c1 is select table_name from dba_tables INTERSECT select table_name from dba_tables@SOME_DBLINKMy need is to pass this dblink as IN parameter to the procedure and use it in the select statement for