- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试访问具有 21 帧的动画 GIF 图像,然后读取第 12 个(因为它从 0 开始?)帧。
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.SuffixFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;
public class PictureSearch {
public static void search(File file) {
try {
ImageReader reader = (ImageReader) ImageIO.getImageReadersBySuffix("gif").next();
reader.setInput(ImageIO.createImageInputStream(file), false);
BufferedImage caption = reader.read(12);
System.out.println(caption.getHeight());
System.out.println(caption.getWidth());
caption.flush();
} catch (IOException e) {
System.out.println(e);
}
}
public static void main(String[] args) throws IOException {
List<String> suffixes = new ArrayList<String>();
suffixes.add(".jpg");
suffixes.add(".gif");
suffixes.add(".bmp");
suffixes.add(".png");
Iterator<File> files = FileUtils.iterateFiles(new File(
"F:/test/"), (IOFileFilter) new SuffixFileFilter(
suffixes), TrueFileFilter.INSTANCE);
while (files.hasNext()) {
File file = (File) files.next();
PictureSearch.search(file);
}
}
}
读者应该返回一个缓冲图像,其高度为 220,宽度为 200(如果忽略图像周围的白色区域,则高度为 205,宽度为 188)。但它的作用是返回一张高度为 155、宽度为 174 的图像,这很荒谬,因为我进行了三重检查,而第 12 帧的高度为 220,宽度为 200。我在阅读框架时所做的一切都正确吗?
最佳答案
您的示例中的矩形看起来是一个帧,表示图像序列的更改部分,从 1 开始。在 Gimp 中打开文件以查看。
附录:它看起来像一个 feature旨在优化渲染。猜测一下,我会说你可以依赖图像编号的边界 getMinIndex()
;后面的帧似乎包含在第一个中。
附录:
is there a way to get the full pixel data with the normal image and changes?
假设几何已知,您应该能够将第一个图像和任何后面的图像合并到一个 BufferedImage
中,如图所示 here .
代码:
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
public class GifBounds {
/** @see https://stackoverflow.com/questions/5688104 */
public static void main(String[] args) throws IOException {
search(new URL("http://i55.tinypic.com/263veb9.gif"));
}
public static void search(URL url) throws IOException {
try {
ImageReader reader = ImageIO.getImageReadersBySuffix("gif").next();
reader.setInput(ImageIO.createImageInputStream(url.openStream()));
int i = reader.getMinIndex();
while (true) {
BufferedImage bi = reader.read(i++);
System.out.println(i
+ ": " + bi.getWidth()
+ ", " + bi.getHeight());
}
} catch (IndexOutOfBoundsException e) {
// ignored
}
}
}
控制台:
1: 200, 2202: 79, 953: 77, 944: 78, 955: 79, 956: 77, 947: 78, 958: 79, 959: 77, 9410: 180, 20511: 97, 11112: 173, 20013: 174, 15514: 174, 15515: 174, 15516: 174, 15517: 174, 15518: 174, 15519: 174, 15520: 167, 20021: 97, 111
关于java - 为什么 ImageReader 返回不正确的 BufferedImage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5688104/
我一整天都在阅读 SO 和 Oracle,以了解如何从 .jpg 图像中提取元数据(提取嵌入在 am 图像中的 GPS 数据)。我所处的环境没有太多第三方库的选择。 我偶然发现了 ImageIO、Im
我遇到了一个问题,我在使用 ImageReader 的同时还使用了一个用于显示相机输出的 SurfaceView。我已经像这样添加了 SurfaceView 本身和 ImageReader 的表面(并
我正在使用 javax.imageio.ImageReader 加载可能较大的图像对于 GUI 中的缩略图生成,以及当用户导航到不同的文件夹(在 Swing 线程上)时,我希望能够中断缩略图生成器的线
我有一些代码使用 ImageReader 类读取大量 TIF 图像。 imageReader 对象是最终对象,并在构造函数中创建。 synchronized(imageReader) { LO
我从动画 gif 中读取了分离的图像,我只需在 frames[i] 中对它们进行更改,然后将它们设置回文件并使用 writer 保存为新文件。 File file = new File("gi
我正在尝试在我的应用程序上实现一个 ImageReader,但我不知道为什么,他什么都不读。 List surfaces = new ArrayList(); Surface prev
我从动画 gif 中读取了分离的图像,我只需在 frames[i] 中对它们进行更改,然后将它们设置回文件并使用 writer 保存为新文件。 File file = new File("gi
我目前正在学习一个github项目ScreenCapture的代码,它可以捕获屏幕并在surfaceview中显示图像,这里是项目https://github.com/Charlesjean/andr
我有一个能够捕获屏幕内容的应用设置。但是,有时,我会从 aquireLatestImage 返回一个 null 值。 .文档说它将返回“如果没有可用的图像数据则为 null”。 我很想知道没有可用图像
我正在尝试使用 camera2 API 从相机捕获图像数据。我主要使用取自 android Capture2RAW 示例的代码。在完全停止之前,只有少数图像通过(即调用 onImageAvailabl
我正在尝试获取多张曝光时间不同的图片来执行我的HDR 算法。但是,我不知道如何在 Android camera2 API 和 ImageReader 中使用 captureBurst() 来保存文件。
我有一个 camera2 实现。当前的设置是,它使用纹理 View 表面来显示实际的相机 View ,并使用 ImageReader 表面来捕获图像。 现在我也想捕捉预览帧。所以我尝试添加一个新的 I
我将 ImageReader 与 Handler 结合使用,以便在背景中获取图像。但我得到: Fatal Exception: java.lang.IllegalStateException maxI
我正在使用 Android ImageReader 类从 MediaProjection.createVirtualDisplay 方法接收位图。 到目前为止,我的代码如下所示: mProjectio
我没有图像或图形方面的背景,所以请耐心等待 :) 我正在使用 JavaCV在我的一个项目中。在examples , 构建了一个 Frame,它有一个 certain size 的缓冲区. 在Andro
我正在尝试访问具有 21 帧的动画 GIF 图像,然后读取第 12 个(因为它从 0 开始?)帧。 import java.awt.image.BufferedImage; import java.i
我正在开发一个 Android 应用程序,我在其中使用 ImageReader 从 Surface 获取图像。当我在 Lollipop 版本中录制屏幕时,表面的数据是从 VirtualDisplay
我尝试实现示例代码片段以从 DicomObject 获取图像: import java.awt.image.BufferedImage; import java.io.BufferedOutputSt
如何通过 ImageReader 将图像读入 base64 编码的字符串? 这是使用 HtmlUnit 的示例源代码。我想获取img的base64字符串: WebClient wc = new W
我正在使用 Android 的 Camera2 API,我想对相机预览帧执行一些图像处理,然后在预览 (TextureView) 上显示更改。 从常见的 camera2video 示例开始,我在我的
我是一名优秀的程序员,十分优秀!