【发布时间】:2013-04-06 17:42:50
【问题描述】:
我有一张尺寸为 16x6080 的图片。这是一个堆叠的图像,其中包含 16x16 部分的国家标志。我的目标是仅从该图像中提取特定国家/地区的标志并将其保存为自己的文件。这是我当前的代码
//Original Image
BufferedImage image = ImageIO.read(new File(countryImageNamePath));
System.out.println("Original Image Dimension: "+image.getWidth()+"x"+image.getHeight());
//Get the cropped image
BufferedImage out = image.getSubimage(0, 1808, 16, 16);
//Create a file to stream the out buffered image to
File croppedFile = new File(countryImagePath + countryName + ".gif");
//Write the cropped file
ImageIO.write(out, "gif", croppedFile);
产生的输出是
Original Image Dimension: 16x6080
Write File : C:\Applications\WorldCoinParser\images\country\US.gif
无论我为 Y 坐标输入什么值,我总是会得到图像的顶部,从 x=0 和 y=0 开始,宽度和高度为 16。
有人知道我在哪里搞砸了吗?
谢谢!
【问题讨论】:
-
我看不出你的sn-p代码有什么明显错误。考虑创建并发布sscce,它使用所有人都可以使用的在线图像。
-
原来这是一个尝试解析 gif 文件的 java 6(及更低版本)中的错误。升级到 Java7 解决了这个问题。
-
好吧,别开玩笑了?!感谢您就此问题与我们联系。考虑将其发布为您问题的答案。
-
由于我是这里的新手,我必须等待 8 小时才能发布答案。今天晚些时候我会更新答案。