2014-03-13 77 views
0

我正在做一個應用程序在Java中,我想這樣做: 我有一個BufferedImage加載一個大圖像,我想分配一部分到另一個BufferedImage將BufferedImage的一部分分配給另一個BufferedImage

比方說

BufferedImage2 = BufferedImage1.GetWindow(From x1 y1 to x2 y2); 

BufferedImage2將是更大BufferedImage1只是一小部分。

+0

什麼是BufferedImage的? GetWindow()返回什麼? – martynas

+1

http://stackoverflow.com/questions/6317732/how-to-get-small-images-from-big-bufferedimage-really-fast – dnault

+1

你正在尋找的方法是'BufferedImage.getSubimage()'http: //stackoverflow.com/questions/22133993/what-exactly-does-getsubimage-of-bufferedimage-do – haraldK

回答

0

你可以嘗試BufferedImage.getSubimage()

int width = x2 - x1; 
int height = y2 - y1; 
BufferedImage bufferedImage2 = bufferedImage1.getSubimage(x1, y1, width, height); 
+0

是的,這是它。謝謝您的幫助 – user3417479

0

例如在圖像緩衝器繪製:

BufferedImage img2 = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 
Graphics2D g = img2.createGraphics(); 
g.drawImage(bufferedImage1, x, y, width, height, null); 
g.dispose(); 

有幾種drawImage方法,請參閱的javadoc。你可能想要這個drawImage

相關問題