类javax.imageio.stream.FileImageInputStream源码实例Demo

下面列出了怎么用javax.imageio.stream.FileImageInputStream的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: java-bot-sdk   文件: ImageUtils.java
public static Dimension getImageDimension(File imgFile) throws IOException {
    int pos = imgFile.getName().lastIndexOf(".");
    if (pos == -1)
        throw new IOException("No extension for file: " + imgFile.getAbsolutePath());
    String suffix = imgFile.getName().substring(pos + 1);
    Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
    while(iter.hasNext()) {
        ImageReader reader = iter.next();
        try {
            ImageInputStream stream = new FileImageInputStream(imgFile);
            reader.setInput(stream);
            int width = reader.getWidth(reader.getMinIndex());
            int height = reader.getHeight(reader.getMinIndex());
            return new Dimension(width, height);
        } catch (IOException e) {
            System.out.println("Error reading: " + imgFile.getAbsolutePath() + " " + e);
        } finally {
            reader.dispose();
        }
    }

    throw new IOException("Not a known image file: " + imgFile.getAbsolutePath());
}
 
源代码2 项目: zserio   文件: AutoOptionalTest.java
private static void checkContainerInFile(File file, int nonOptionalIntValue, Integer autoOptionalIntValue)
        throws IOException
{
    final FileImageInputStream stream = new FileImageInputStream(file);

    if (autoOptionalIntValue == null)
    {
        assertEquals((CONTAINER_BIT_SIZE_WITHOUT_OPTIONAL + 7) / Byte.SIZE, stream.length());
        assertEquals(nonOptionalIntValue, (int) stream.readBits(32));
        assertEquals(0, stream.readBit());
    }
    else
    {
        assertEquals((CONTAINER_BIT_SIZE_WITH_OPTIONAL + 7) / Byte.SIZE, stream.length());
        assertEquals(nonOptionalIntValue, (int) stream.readBits(32));
        assertEquals(1, stream.readBit());
        assertEquals((int) autoOptionalIntValue, (int) stream.readBits(32));
    }

    stream.close();
}
 
源代码3 项目: zserio   文件: OptionalExpressionTest.java
private static void checkContainerInFile(File file, BasicColor basicColor, short numBlackTones)
        throws IOException
{
    final FileImageInputStream stream = new FileImageInputStream(file);

    if (basicColor == BasicColor.WHITE)
    {
        assertEquals(1, stream.length());
        assertEquals(basicColor.getValue(), stream.readByte());
    }
    else
    {
        assertEquals(1 + 1 + 4 * numBlackTones, stream.length());
        assertEquals(basicColor.getValue(), stream.readByte());
        assertEquals(numBlackTones, stream.readByte());
        for (short i = 0; i < numBlackTones; ++i)
            assertEquals(i + 1, stream.readInt());
    }

    stream.close();
}
 
源代码4 项目: instagram4j   文件: InstagramGenericUtil.java
/**
 * Gets image dimensions for given file
 * 
 * @param imgFile image file
 * @return dimensions of image
 * @throws IOException if the file is not a known image
 */
public static Dimension getImageDimension(File imgFile) throws IOException {
	int pos = imgFile.getName().lastIndexOf(".");
	if (pos == -1)
		throw new IOException("No extension for file: " + imgFile.getAbsolutePath());
	String suffix = imgFile.getName().substring(pos + 1);
	Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
	while (iter.hasNext()) {
		ImageReader reader = iter.next();
		try {
			ImageInputStream stream = new FileImageInputStream(imgFile);
			reader.setInput(stream);
			int width = reader.getWidth(reader.getMinIndex());
			int height = reader.getHeight(reader.getMinIndex());
			return new Dimension(width, height);
		} catch (IOException e) {
			log.warn("Error reading: " + imgFile.getAbsolutePath(), e);
		} finally {
			reader.dispose();
		}
	}

	throw new IOException("Not a known image file: " + imgFile.getAbsolutePath());
}
 
源代码5 项目: openjdk-jdk9   文件: ImageStreamFromRAF.java
public static void main(String[] args) {
    try {
        File f = new File("ImageInputStreamFromRAF.tmp");
        RandomAccessFile raf = new RandomAccessFile(f, "rw");
        ImageInputStream istream = ImageIO.createImageInputStream(raf);
        ImageOutputStream ostream = ImageIO.createImageOutputStream(raf);
        f.delete();
        if (istream == null) {
            throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) returned null!");
        }
        if (ostream == null) {
            throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) returned null!");
        }
        if (!(istream instanceof FileImageInputStream)) {
            throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) did not return a FileImageInputStream!");
        }
        if (!(ostream instanceof FileImageOutputStream)) {
            throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) did not return a FileImageOutputStream!");
        }
    } catch (IOException ioe) {
        throw new RuntimeException("Unexpected IOException: " + ioe);
    }
}
 
源代码6 项目: j-webp   文件: DecodeTest.java
public static void main(String args[]) throws IOException {
    String inputWebpPath = "test_pic/test.webp";
    String outputJpgPath = "test_pic/test_.jpg";
    String outputJpegPath = "test_pic/test_.jpeg";
    String outputPngPath = "test_pic/test_.png";

    // Obtain a WebP ImageReader instance
    ImageReader reader = ImageIO.getImageReadersByMIMEType("image/webp").next();

    // Configure decoding parameters
    WebPReadParam readParam = new WebPReadParam();
    readParam.setBypassFiltering(true);

    // Configure the input on the ImageReader
    reader.setInput(new FileImageInputStream(new File(inputWebpPath)));

    // Decode the image
    BufferedImage image = reader.read(0, readParam);

    ImageIO.write(image, "png", new File(outputPngPath));
    ImageIO.write(image, "jpg", new File(outputJpgPath));
    ImageIO.write(image, "jpeg", new File(outputJpegPath));

}
 
源代码7 项目: density-converter   文件: ImageUtil.java
/**
 * Gets image dimensions for given file
 *
 * @param imgFile image file
 * @return dimensions of image
 * @throws IOException if the file is not a known image
 */
public static Dimension getImageDimension(File imgFile) throws IOException {
    int pos = imgFile.getName().lastIndexOf(".");
    if (pos == -1)
        throw new IOException("No extension for file: " + imgFile.getAbsolutePath());
    String suffix = imgFile.getName().substring(pos + 1);
    Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
    if (iter.hasNext()) {
        ImageReader reader = iter.next();
        try {
            ImageInputStream stream = new FileImageInputStream(imgFile);
            reader.setInput(stream);
            int width = reader.getWidth(reader.getMinIndex());
            int height = reader.getHeight(reader.getMinIndex());
            return new Dimension(width, height);
        } finally {
            reader.dispose();
        }
    }

    throw new IOException("Not a known image file: " + imgFile.getAbsolutePath());
}
 
源代码8 项目: jdk8u_jdk   文件: ImageStreamFromRAF.java
public static void main(String[] args) {
    try {
        File f = new File("ImageInputStreamFromRAF.tmp");
        RandomAccessFile raf = new RandomAccessFile(f, "rw");
        ImageInputStream istream = ImageIO.createImageInputStream(raf);
        ImageOutputStream ostream = ImageIO.createImageOutputStream(raf);
        f.delete();
        if (istream == null) {
            throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) returned null!");
        }
        if (ostream == null) {
            throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) returned null!");
        }
        if (!(istream instanceof FileImageInputStream)) {
            throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) did not return a FileImageInputStream!");
        }
        if (!(ostream instanceof FileImageOutputStream)) {
            throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) did not return a FileImageOutputStream!");
        }
    } catch (IOException ioe) {
        throw new RuntimeException("Unexpected IOException: " + ioe);
    }
}
 
源代码9 项目: skin-composer   文件: Utils.java
public static boolean doesImageFitBox(FileHandle fileHandle, float width, float height) {
    boolean result = false;
    String suffix = fileHandle.extension();
    Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
    if (iter.hasNext()) {
        ImageReader reader = iter.next();
        try (var stream = new FileImageInputStream(fileHandle.file())) {
            reader.setInput(stream);
            int imageWidth = reader.getWidth(reader.getMinIndex());
            int imageHeight = reader.getHeight(reader.getMinIndex());
            result = imageWidth < width && imageHeight < height;
        } catch (IOException e) {
            Gdx.app.error(Utils.class.getName(), "error checking image dimensions", e);
        } finally {
            reader.dispose();
        }
    } else {
        Gdx.app.error(Utils.class.getName(), "No reader available to check image dimensions");
    }
    return result;
}
 
源代码10 项目: dashencrypt   文件: ManifestCreation.java
private static Dimension getImageDimension(File imgFile) throws IOException {
    int pos = imgFile.getName().lastIndexOf(".");
    if (pos == -1)
        throw new IOException("No extension for file: " + imgFile.getAbsolutePath());
    String suffix = imgFile.getName().substring(pos + 1);
    Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
    while (iter.hasNext()) {
        ImageReader reader = iter.next();
        try {
            ImageInputStream stream = new FileImageInputStream(imgFile);
            reader.setInput(stream);
            int width = reader.getWidth(reader.getMinIndex());
            int height = reader.getHeight(reader.getMinIndex());
            return new Dimension(width, height);
        } catch (IOException e) {
            LOG.log(Level.WARNING, "Error reading: " + imgFile.getAbsolutePath(), e);
        } finally {
            reader.dispose();
        }
    }

    throw new IOException("Not a known image file: " + imgFile.getAbsolutePath());
}
 
源代码11 项目: WorldPainter   文件: Dimension.java
private java.awt.Dimension getImageSize(File image) throws IOException {
    String filename = image.getName();
    int p = filename.lastIndexOf('.');
    if (p == -1) {
        return null;
    }
    String suffix = filename.substring(p + 1).toLowerCase();
    Iterator<ImageReader> readers = ImageIO.getImageReadersBySuffix(suffix);
    if (readers.hasNext()) {
        ImageReader reader = readers.next();
        try {
            try (ImageInputStream in = new FileImageInputStream(image)) {
                reader.setInput(in);
                int width = reader.getWidth(reader.getMinIndex());
                int height = reader.getHeight(reader.getMinIndex());
                return new java.awt.Dimension(width, height);
            }
        } finally {
            reader.dispose();
        }
    } else {
        return null;
    }
}
 
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir) {
    if (input instanceof File) {
        try {
            return new FileImageInputStream((File)input);
        } catch (Exception e) {
            return null;
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir) {
    if (input instanceof RandomAccessFile) {
        try {
            return new FileImageInputStream((RandomAccessFile)input);
        } catch (Exception e) {
            return null;
        }
    } else {
        throw new IllegalArgumentException
            ("input not a RandomAccessFile!");
    }
}
 
源代码14 项目: dragonwell8_jdk   文件: FileImageInputStreamSpi.java
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir) {
    if (input instanceof File) {
        try {
            return new FileImageInputStream((File)input);
        } catch (Exception e) {
            return null;
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
源代码15 项目: dragonwell8_jdk   文件: RAFImageInputStreamSpi.java
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir) {
    if (input instanceof RandomAccessFile) {
        try {
            return new FileImageInputStream((RandomAccessFile)input);
        } catch (Exception e) {
            return null;
        }
    } else {
        throw new IllegalArgumentException
            ("input not a RandomAccessFile!");
    }
}
 
源代码16 项目: TencentKona-8   文件: FileImageInputStreamSpi.java
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir) {
    if (input instanceof File) {
        try {
            return new FileImageInputStream((File)input);
        } catch (Exception e) {
            return null;
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
源代码17 项目: TencentKona-8   文件: RAFImageInputStreamSpi.java
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir) {
    if (input instanceof RandomAccessFile) {
        try {
            return new FileImageInputStream((RandomAccessFile)input);
        } catch (Exception e) {
            return null;
        }
    } else {
        throw new IllegalArgumentException
            ("input not a RandomAccessFile!");
    }
}
 
源代码18 项目: jdk8u60   文件: FileImageInputStreamSpi.java
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir) {
    if (input instanceof File) {
        try {
            return new FileImageInputStream((File)input);
        } catch (Exception e) {
            return null;
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
源代码19 项目: jdk8u60   文件: RAFImageInputStreamSpi.java
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir) {
    if (input instanceof RandomAccessFile) {
        try {
            return new FileImageInputStream((RandomAccessFile)input);
        } catch (Exception e) {
            return null;
        }
    } else {
        throw new IllegalArgumentException
            ("input not a RandomAccessFile!");
    }
}
 
源代码20 项目: JDKSourceCode1.8   文件: FileImageInputStreamSpi.java
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir) {
    if (input instanceof File) {
        try {
            return new FileImageInputStream((File)input);
        } catch (Exception e) {
            return null;
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
源代码21 项目: JDKSourceCode1.8   文件: RAFImageInputStreamSpi.java
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir) {
    if (input instanceof RandomAccessFile) {
        try {
            return new FileImageInputStream((RandomAccessFile)input);
        } catch (Exception e) {
            return null;
        }
    } else {
        throw new IllegalArgumentException
            ("input not a RandomAccessFile!");
    }
}
 
源代码22 项目: zserio   文件: SimpleParamTest.java
private void checkItemInFile(File file, Item item, long version) throws IOException
{
    final FileImageInputStream stream = new FileImageInputStream(file);
    assertEquals(item.getParam(), stream.readUnsignedShort());
    if (version >= HIGHER_VERSION)
        assertEquals(item.getExtraParam(), Long.valueOf(stream.readUnsignedInt()));
    stream.close();
}
 
源代码23 项目: openjdk-jdk8u   文件: FileImageInputStreamSpi.java
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir) {
    if (input instanceof File) {
        try {
            return new FileImageInputStream((File)input);
        } catch (Exception e) {
            return null;
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
源代码24 项目: openjdk-jdk8u   文件: RAFImageInputStreamSpi.java
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir) {
    if (input instanceof RandomAccessFile) {
        try {
            return new FileImageInputStream((RandomAccessFile)input);
        } catch (Exception e) {
            return null;
        }
    } else {
        throw new IllegalArgumentException
            ("input not a RandomAccessFile!");
    }
}
 
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir) {
    if (input instanceof File) {
        try {
            return new FileImageInputStream((File)input);
        } catch (Exception e) {
            return null;
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir) {
    if (input instanceof RandomAccessFile) {
        try {
            return new FileImageInputStream((RandomAccessFile)input);
        } catch (Exception e) {
            return null;
        }
    } else {
        throw new IllegalArgumentException
            ("input not a RandomAccessFile!");
    }
}
 
源代码27 项目: Bytecoder   文件: FileImageInputStreamSpi.java
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir) {
    if (input instanceof File) {
        try {
            return new FileImageInputStream((File)input);
        } catch (Exception e) {
            return null;
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
源代码28 项目: Bytecoder   文件: RAFImageInputStreamSpi.java
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir) {
    if (input instanceof RandomAccessFile) {
        try {
            return new FileImageInputStream((RandomAccessFile)input);
        } catch (Exception e) {
            return null;
        }
    } else {
        throw new IllegalArgumentException
            ("input not a RandomAccessFile!");
    }
}
 
源代码29 项目: openjdk-jdk9   文件: FileImageInputStreamSpi.java
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir) {
    if (input instanceof File) {
        try {
            return new FileImageInputStream((File)input);
        } catch (Exception e) {
            return null;
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
源代码30 项目: openjdk-jdk9   文件: RAFImageInputStreamSpi.java
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir) {
    if (input instanceof RandomAccessFile) {
        try {
            return new FileImageInputStream((RandomAccessFile)input);
        } catch (Exception e) {
            return null;
        }
    } else {
        throw new IllegalArgumentException
            ("input not a RandomAccessFile!");
    }
}
 
 类所在包
 类方法
 同包方法