當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。