如何使用工具包使用获取图像检索裁剪的图像?

时间:2012-04-12 14:40:55

标签: java eclipse

image = ImageIO.read(new File("C:/Graphics/src/name2.jpg"));         

ImageFilter filter = new CropImageFilter(0, 0, 250, 250);
    ImageProducer producer = new FilteredImageSource(image.getSource(), filter);

Image resultImage = Toolkit.getDefaultToolkit().createImage(
    producer);
ImageIO.write(resultImage, "jpg", 
    new File("C:/Graphics/src/name7.jpg"));  //not allowing me  

//这是行显示错误:

The method write(RenderedImage, String, File) in the type ImageIO is not 
    applicable for the arguments (Image, String, File)

1 个答案:

答案 0 :(得分:0)

请参阅BufferedImage.html#getSubimage(x,y,,w,h)了解子图像。

要获得BufferedImage,请使用ImageIO.read(File/InputStream/URL)


The method write(RenderedImage, String, File) in the type ImageIO is not 
    applicable for the arguments (Image, String, File)

image显然被声明为Image,将其更改为:

BufferedImage image = ImageIO.read(new File("C:/Graphics/src/name2.jpg"));