2014-03-13 75 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

相关问题