Skip to main content

Vector image from clipboard

No replies
ragsetty
Offline
Joined: 2008-01-07

Hi all,

I have written below code to get the image from clipboard.

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

Clipboard clipboard = getToolkit().getSystemClipboard();
Transferable clipboardContent = clipboard.getContents(this);
Image tempImage = (Image) clipboardContent.getTransferData(DataFlavor.imageFlavor);
int width = tempImage.getWidth(null);
int height = tempImage.getHeight(null);

BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = bi.createGraphics();
g2.drawImage(tempImage, 0, 0, null);
g2.dispose();

ImageIO.write(bi, "jpg", new File("C:/temp/image.jpg"));

This is gets me a "Raster Image". I actually need to create a "Vector Image" (svg or mwf) from the image which is there in system clipboard.

Please guide me how to get a Vector Image or to convert the existing Raster Image.

Thanks in advance,
Rag Setty