Skip to main content

Images and clipboard

3 replies [Last post]
j_acon
Offline
Joined: 2005-09-21
Points: 0

I am trying to add a selected area of an image to the clipboard.

public void copyIntoClipboard(int width, int height)
{
RenderingHints hints = new RenderingHints(null);
hints.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
hints.add(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON));
hints.add(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
hints.add(new RenderingHints(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE));

ParameterBlock pb = new ParameterBlock();
pb.addSource(display.getSource());
pb.add((float)originPoint.x);
pb.add((float)originPoint.y);
pb.add((float)width);
pb.add((float)height);
Image image = JAI.create("crop", pb, hints).getAsBufferedImage();
ImageSelection imageSelection = new ImageSelection(image);

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(imageSelection, null);
}

but i get this error.
Exception in thread "AWT-EventQueue-1" java.awt.image.ImagingOpException: Unable to transform src image

but if i do

Toolkit toolkit = Toolkit.getDefaultToolkit();
Image image = toolkit.getImage("c:\\candy.jpg");
ImageSelection imageSelection = new ImageSelection(image);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(imageSelection, null);

The thing works. The main this difference, is that i am modifying the images on the first method and on the second method i just retrieve the image. Anyone knows a way around this?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
j_acon
Offline
Joined: 2005-09-21
Points: 0

Found out that i can add any image to the clipboard, just can't add them after i crop them. But i tested the cropping method and it does crop the image. Is the image getting corrupted after the cropping?

Stéphane Wasserhardt

Try to translate the cropped image back to (0,0) before using ImageSelection
(translation with values -originPoint.x and -originPoint.y)
Hope this help !

Regards,
Stephane

-----Message d'origine-----
De : jai-interest@javadesktop.org [mailto:jai-interest@javadesktop.org]
Envoyé : mardi 5 juillet 2005 09:09
À : interest@jai.dev.java.net
Objet : [JAI] Re: Images and clipboard

Found out that i can add any image to the clipboard, just can't add them after i crop them. But i tested the cropping method and it does crop the image. Is the image getting corrupted after the cropping?
---
[Message sent by forum member 'j_acon' (Jorge)]

http://www.javadesktop.org/forums/thread.jspa?messageID=97339&#97339

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

j_acon
Offline
Joined: 2005-09-21
Points: 0

Woot thanks, working now :)