当前位置: 首页>>代码示例>>Java>>正文


Java ImageReader.getNumImages方法代码示例

本文整理汇总了Java中javax.imageio.ImageReader.getNumImages方法的典型用法代码示例。如果您正苦于以下问题:Java ImageReader.getNumImages方法的具体用法?Java ImageReader.getNumImages怎么用?Java ImageReader.getNumImages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.imageio.ImageReader的用法示例。


在下文中一共展示了ImageReader.getNumImages方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFrames

import javax.imageio.ImageReader; //导入方法依赖的package包/类
static ArrayList<BufferedImage> getFrames(File gif) throws IOException {
    ArrayList<BufferedImage> frames = new ArrayList<BufferedImage>();
    ImageReader ir = new GIFImageReader(new GIFImageReaderSpi());
    ir.setInput(ImageIO.createImageInputStream(gif));
    for (int i = 0; i < ir.getNumImages(true); i++) {
        frames.add(ir.read(i));
    }
    // Release resources for Garbage Collection
    ir.dispose();
    return frames;
}
 
开发者ID:phweda,项目名称:MFM,代码行数:12,代码来源:VideoUtils.java

示例2: getPngFrames

import javax.imageio.ImageReader; //导入方法依赖的package包/类
private static List<InputStream> getPngFrames(ImageInputStream imageInputStream) {
    List<InputStream> result = new ArrayList<>();
    try {
        ImageReader reader = ImageIO.getImageReadersByFormatName("gif").next();
        reader.setInput(imageInputStream);
        int count = reader.getNumImages(true);
        for (int index = 0; index < count; index++) {
            BufferedImage frame = reader.read(index);
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            ImageIO.write(frame, "png", os);
            InputStream is = new ByteArrayInputStream(os.toByteArray());
            result.add(is);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:19,代码来源:GifFramesExtractor.java

示例3: test

import javax.imageio.ImageReader; //导入方法依赖的package包/类
private static void test(ImageReader reader, String format)
    throws IOException {
    boolean gotISE = false;
    File f = null;
    ImageInputStream stream = null;
    try {
        f = File.createTempFile("imageio", ".tmp");
        stream = ImageIO.createImageInputStream(f);
        reader.setInput(stream, true);

        try {
            int numImages = reader.getNumImages(true);
        } catch (IOException ioe) {
            gotISE = false;
        } catch (IllegalStateException ise) {
            gotISE = true;
        }
    } finally {
        if (stream != null) {
            stream.close();
        }

        reader.dispose();

        if (f != null) {
            Files.delete(f.toPath());
        }
    }

    if (!gotISE) {
        throw new RuntimeException("Failed to get desired exception for " +
                                   format + " reader!");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:AllowSearch.java

示例4: checkAnimation

import javax.imageio.ImageReader; //导入方法依赖的package包/类
protected void checkAnimation() throws IOException {
    ImageReader r = ImageIO.getImageReadersByFormatName("GIF").next();
    r.setInput(ImageIO.createImageInputStream(new File(fname)));

    int n = r.getNumImages(true);
    for (int i = 0; i < n; i++) {
        BufferedImage f = r.read(i);
        checkFrame(i, f);
    }
    System.out.println("Test passed.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:AnimationTest.java

示例5: Texture

import javax.imageio.ImageReader; //导入方法依赖的package包/类
public Texture(ResourceLocation location, boolean allowRP)
{
    InputStream s = null;
    try
    {
        this.location = location;
        s = open(location, allowRP);
        ImageInputStream stream = ImageIO.createImageInputStream(s);
        Iterator<ImageReader> readers = ImageIO.getImageReaders(stream);
        if(!readers.hasNext()) throw new IOException("No suitable reader found for image" + location);
        ImageReader reader = readers.next();
        reader.setInput(stream);
        frames = reader.getNumImages(true);
        BufferedImage[] images = new BufferedImage[frames];
        for(int i = 0; i < frames; i++)
        {
            images[i] = reader.read(i);
        }
        reader.dispose();
        int size = 1;
        width = images[0].getWidth();
        height = images[0].getHeight();
        while((size / width) * (size / height) < frames) size *= 2;
        this.size = size;
        glEnable(GL_TEXTURE_2D);
        synchronized(SplashProgress.class)
        {
            name = glGenTextures();
            glBindTexture(GL_TEXTURE_2D, name);
        }
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size, size, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, (IntBuffer)null);
        checkGLError("Texture creation");
        for(int i = 0; i * (size / width) < frames; i++)
        {
            for(int j = 0; i * (size / width) + j < frames && j < size / width; j++)
            {
                buf.clear();
                BufferedImage image = images[i * (size / width) + j];
                for(int k = 0; k < height; k++)
                {
                    for(int l = 0; l < width; l++)
                    {
                        buf.put(image.getRGB(l, k));
                    }
                }
                buf.position(0).limit(width * height);
                glTexSubImage2D(GL_TEXTURE_2D, 0, j * width, i * height, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, buf);
                checkGLError("Texture uploading");
            }
        }
        glBindTexture(GL_TEXTURE_2D, 0);
        glDisable(GL_TEXTURE_2D);
    }
    catch(IOException e)
    {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    finally
    {
        IOUtils.closeQuietly(s);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:66,代码来源:SplashProgress.java


注:本文中的javax.imageio.ImageReader.getNumImages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。