2010-04-26 4 views

답변

1

BufferedImage를 만든 다음 ImageIO.write (image, "gif", fileName)으로 파일에 씁니다. 이미 이미지 파일 또는 이미지 URL이있는 경우

1

, 당신은 얻을 Toolkit를 사용할 수있는 Image :

 
Image img = Toolkit . getDefaultToolkit() . createImage (filename); 

새 이미지 래스터를 구성하고 이미지로 칠해야하는 경우에, 당신이 할 수있는 BufferedImage을 사용하십시오. createGraphics 함수를 호출하고 그래픽 객체에 그림을 그려 BufferedImage에 페인트 할 수 있습니다. BufferedImage를 GIF에 저장하려면 ImageIO 클래스를 사용하여 이미지를 쓸 수 있습니다.

+0

이미지를 읽는 데 Toolkit을 사용하는 방법은 더 이상 사용되지 않습니다. – Roman

+0

@Roman, 새로운 길은 무엇입니까? –

1

가장 좋은 방법은 BufferedImage 생성하는 것입니다

Graphics2D g = img.createGraphics(); 
g.setBackground(Color color) ; //Find how to built this object look at the java api 
g.draw(Shape s); 
g.dispose(); //don't forget it!!! 

사람 :

다음
BufferedImage img = new BufferedImage(int width, int height, int imageType) 
// you can find the Types variables in the api 

,이 이미지의 Graphics2D을 생성,이 객체는 배경을 설정하고 모양을 그릴 수 있습니다 이미지를 만들었습니다 :

File file = new File(dir, name); 
try{ 
    ImageIO.write(img, "gif", file); 
}catch(IOException e){ 
    e.printStackTrace(); 
} 
관련 문제