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)
答案 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"));