I’m making a program using java that sends the clipboard contents over sockets; I managed to make it work with strings but I’m having some troubles with images. Here is the code:
//get Image
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Image imageContents = (Image)clipboard.getData(DataFlavor.imageFlavor);
ImageIcon image = new ImageIcon(imageContents);
//sent over sockets
//set Image
String mime = DataFlavor.imageFlavor.getMimeType();
DataHandler contents = new DataHandler(image,mime);
//set clipboard
clipboard.setContents(contents, null);
After setContents the clipboard is empty; Any ideas why, and how to fix it?
Here is some code I’ve used to write/read an Image from the clipboard. Never tried it with sockets so I’m not sure it will help: