2016-04-11 58 views
0

我有一個圖像800x480。如何創建下列座標115,235,580,202(x,y,寬度,高度)的新子圖像?用Java創建子圖像

+1

一切皆有可能。你到目前爲止嘗試了什麼? – Norman

+0

謝謝諾曼,私人Image createImage(){ BufferedImage bi = new BufferedImage(800,480,BufferedImage.TYPE_INT_RGB); Graphics2D g =(Graphics2D)bi.getGraphics(); g.fillRect(0,0,bi.getWidth(),bi.getHeight()); – ezzitt

回答

1

你可以使用BufferedImage,請執行以下操作來獲得子圖像:

BufferedImage img = ImageIO.read(new File("yourPath")); 
BufferedImage subimage = img.getSubimage(115, 235, 580, 202); 
ImageIO.write(subimage, "png", new File("outputPath")); 

本例將文件系統,你也可以使用流。