简体   繁体   English

java创建一个BufferedImage并从中获取一个子图像

[英]java creating a BufferedImage and taking a subimage from it

I want to be able to get a BufferedImage from a URL / a File and then return a subimage from it. 我希望能够从URL /文件获取BufferedImage,然后从中返回子图像。 The first issue is that when i try it with 第一个问题是当我尝试使用

BufferedImage b = null;   
b = ImageIO.read("url");

b just stays null. b保持为空。

Can anyone explain to me how to successfully initialize a BufferedImage, so that I can then get a subimage of it using 谁能向我解释如何成功初始化BufferedImage,以便随后可以使用它获取子图像

BufferedImage c = b.getSubimage(0, 0, 20, 20);

I found it now by myself :^) I just did this : 我现在自己找到了它:^)我只是这样做了:

img = ImageIO.read(new File(filePath));
BufferedImage img2 = img.getSubimage(0,0,100,100);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM