JAVA From RenderedImage To BufferedImage

2009. 6. 18. 10:37프로그래밍/Java

반응형

[CODE]
 // 참고 URL : http://www.jguru.com/faq/view.jsp?EID=114602
 public static BufferedImage convertRenderedImage(RenderedImage img) {
  if (img instanceof BufferedImage) {
   return (BufferedImage)img; 
  } 
  ColorModel cm = img.getColorModel();
  int width = img.getWidth();
  int height = img.getHeight();
  WritableRaster raster = cm.createCompatibleWritableRaster(width, height);
  boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
  Hashtable properties = new Hashtable();
  String[] keys = img.getPropertyNames();
  if (keys!=null) {
   for (int i = 0; i < keys.length; i++) {
    properties.put(keys[i], img.getProperty(keys[i]));
   }
  }
  BufferedImage result = new BufferedImage(cm, raster, isAlphaPremultiplied, properties);
  img.copyData(raster);
  return result;
 }
[/CODE]
반응형