Java Tutorial/2D Graphics/ImageWriter — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 15:25, 31 мая 2010
Write Image with ImageWriter
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream;
public class Main {
static public void main(String args[]) throws Exception {
int width = 200, height = 200;
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D ig2 = bi.createGraphics();
ig2.fillRect(0, 0, width - 1, height - 1);
Iterator imageWriters = ImageIO.getImageWritersByFormatName("GIF");
ImageWriter imageWriter = (ImageWriter) imageWriters.next();
File file = new File("filename.gif");
ImageOutputStream ios = ImageIO.createImageOutputStream(file);
imageWriter.setOutput(ios);
imageWriter.write(bi);
}
}