I think these options can't be performed at the same time because windows clipboard only can hold one item (picture or text).
-ralfs
That's just wrong. (Even for text there are already four different formats in the clipboard, see the screenshot of the clipboard viewer in my previous post).
I just verified that the clipboard can also hold image and text formats at the same time: I wrote a small Java program that does exactly that.
When I run the code,
then paste into Paint.NET I get an image:
[attach=#1][/attach]
Paste into Word gets the text:
[attach=#2][/attach]
BTW my use case is: I am frequently using two issue trackers: YouTrack which has an option "Attach Image from Clipboard" and Jira where I need to upload a file. It would be nice to have the screenshot in both formats automatically, so that I can immediately use it on either bug tracker.
Main:
package de.eekboom.cliptest;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.image.BufferedImage;
public class Main {
public static void main(String[] args) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
BufferedImage bufferedImage = createImage();
TextAndImageContent content = new TextAndImageContent("Text & Image in Clipboard", bufferedImage);
clipboard.setContents(content, null);
}
private static BufferedImage createImage() {
BufferedImage bufferedImage = new BufferedImage(80, 40, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = bufferedImage.createGraphics();
graphics.setPaint(Color.RED);
graphics.fillOval(5, 5, 70, 30);
return bufferedImage;
}
}
Helper class:
package de.eekboom.cliptest;
import java.awt.datatransfer.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
public class TextAndImageContent implements Transferable, ClipboardOwner {
private final String text;
private final BufferedImage image;
private static final DataFlavor[] flavors = {
DataFlavor.stringFlavor,
DataFlavor.imageFlavor
};
public TextAndImageContent(String text, BufferedImage image) {
this.text = text;
this.image = image;
}
@Override
public DataFlavor[] getTransferDataFlavors() {
return (DataFlavor[])flavors.clone();
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
for (DataFlavor supportedFlavor : flavors) {
if (flavor.equals(supportedFlavor)) {
return true;
}
}
return false;
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (flavor.equals(DataFlavor.stringFlavor)) {
return text;
}
if (flavor.equals(DataFlavor.imageFlavor)) {
return image;
}
return null;
}
@Override
public void lostOwnership(Clipboard clipboard, Transferable contents) {
}
}