SVG ?
http://www.w3.org/Graphics/SVG/
SVG 를 활용하는 간단한 샘플코드.
package image;
import java.awt.image.renderable.ParameterBlock;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.URL;
import javax.media.jai.Interpolation;
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import javax.media.jai.operator.ScaleDescriptor;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
public class SVGUtil {
public static void imgToSvg(String imgPath, String svgPath, int destWidth, int destHeight) throws Exception{
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
String svgNS = "http://www.w3.org/2000/svg";
Document document = domImpl.createDocument(svgNS, "svg", null);
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
ParameterBlock pb = new ParameterBlock();
pb.add(imgPath);
PlanarImage image = JAI.create("fileload", pb);
float xScale = (float) destWidth / image.getWidth();
float yScale = (float) destHeight / image.getHeight();
PlanarImage renderedOp = ScaleDescriptor.create(image, new Float(xScale), new Float(yScale), new Float(0.0f), new Float(0.0f), Interpolation.getInstance(Interpolation.INTERP_BICUBIC), null);
svgGenerator.drawImage(renderedOp.getAsBufferedImage(), 0, 0,renderedOp.getAsBufferedImage().getWidth(), renderedOp.getAsBufferedImage().getHeight(), null);
svgGenerator.dispose();
Writer out = new OutputStreamWriter(new FileOutputStream(new File(svgPath)), "UTF-8");
svgGenerator.stream(out, false);
out.flush();
out.close();
}
public static void main(String[] args) {
try {
long start = System.currentTimeMillis();
ClassLoader cl;
cl = Thread.currentThread().getContextClassLoader();
if( cl == null )
cl = ClassLoader.getSystemClassLoader();
URL defaultPath = cl.getResource( "" );
imgToSvg(defaultPath.getPath() + "test.jpg" , defaultPath.getPath() +"test.svg", 320, 280);
long end = System.currentTimeMillis();
long elapsed = end - start;
System.out.print( "-----> " + ((double)elapsed / 1000.0) );
} catch(Exception e) {
e.printStackTrace();
}
}
}
댓글 없음:
댓글 쓰기