javax.imageio.ImageReader#getImageTypes ( )源码实例Demo

下面列出了javax.imageio.ImageReader#getImageTypes ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: ReadAsGrayTest.java
private static void doTest(int type) throws IOException {
    BufferedImage src = createTestImage(type);

    File f = new File("test.jpg");

    if (!ImageIO.write(src, "jpg", f)) {
        throw new RuntimeException("Failed to write test image.");
    }

    ImageInputStream iis = ImageIO.createImageInputStream(f);
    ImageReader reader = ImageIO.getImageReaders(iis).next();
    reader.setInput(iis);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    ImageTypeSpecifier srgb = null;
    ImageTypeSpecifier gray = null;
    // look for gray and srgb types
    while ((srgb == null || gray == null) && types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        if (t.getColorModel().getColorSpace().getType() == TYPE_GRAY) {
            gray = t;
        }
        if (t.getColorModel().getColorSpace() == sRGB) {
            srgb = t;
        }
    }
    if (gray == null) {
        throw new RuntimeException("No gray type available.");
    }
    if (srgb == null) {
        throw new RuntimeException("No srgb type available.");
    }

    System.out.println("Read as GRAY...");
    testType(reader, gray, src);

    System.out.println("Read as sRGB...");
    testType(reader, srgb, src);
}
 
源代码2 项目: TencentKona-8   文件: ReadAsGrayTest.java
private static void doTest(int type) throws IOException {
    BufferedImage src = createTestImage(type);

    File f = new File("test.jpg");

    if (!ImageIO.write(src, "jpg", f)) {
        throw new RuntimeException("Failed to write test image.");
    }

    ImageInputStream iis = ImageIO.createImageInputStream(f);
    ImageReader reader = ImageIO.getImageReaders(iis).next();
    reader.setInput(iis);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    ImageTypeSpecifier srgb = null;
    ImageTypeSpecifier gray = null;
    // look for gray and srgb types
    while ((srgb == null || gray == null) && types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        if (t.getColorModel().getColorSpace().getType() == TYPE_GRAY) {
            gray = t;
        }
        if (t.getColorModel().getColorSpace() == sRGB) {
            srgb = t;
        }
    }
    if (gray == null) {
        throw new RuntimeException("No gray type available.");
    }
    if (srgb == null) {
        throw new RuntimeException("No srgb type available.");
    }

    System.out.println("Read as GRAY...");
    testType(reader, gray, src);

    System.out.println("Read as sRGB...");
    testType(reader, srgb, src);
}
 
源代码3 项目: jdk8u60   文件: ReadAsGrayTest.java
private static void doTest(int type) throws IOException {
    BufferedImage src = createTestImage(type);

    File f = new File("test.jpg");

    if (!ImageIO.write(src, "jpg", f)) {
        throw new RuntimeException("Failed to write test image.");
    }

    ImageInputStream iis = ImageIO.createImageInputStream(f);
    ImageReader reader = ImageIO.getImageReaders(iis).next();
    reader.setInput(iis);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    ImageTypeSpecifier srgb = null;
    ImageTypeSpecifier gray = null;
    // look for gray and srgb types
    while ((srgb == null || gray == null) && types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        if (t.getColorModel().getColorSpace().getType() == TYPE_GRAY) {
            gray = t;
        }
        if (t.getColorModel().getColorSpace() == sRGB) {
            srgb = t;
        }
    }
    if (gray == null) {
        throw new RuntimeException("No gray type available.");
    }
    if (srgb == null) {
        throw new RuntimeException("No srgb type available.");
    }

    System.out.println("Read as GRAY...");
    testType(reader, gray, src);

    System.out.println("Read as sRGB...");
    testType(reader, srgb, src);
}
 
源代码4 项目: openjdk-jdk8u   文件: ReadAsGrayTest.java
private static void doTest(int type) throws IOException {
    BufferedImage src = createTestImage(type);

    File f = new File("test.jpg");

    if (!ImageIO.write(src, "jpg", f)) {
        throw new RuntimeException("Failed to write test image.");
    }

    ImageInputStream iis = ImageIO.createImageInputStream(f);
    ImageReader reader = ImageIO.getImageReaders(iis).next();
    reader.setInput(iis);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    ImageTypeSpecifier srgb = null;
    ImageTypeSpecifier gray = null;
    // look for gray and srgb types
    while ((srgb == null || gray == null) && types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        if (t.getColorModel().getColorSpace().getType() == TYPE_GRAY) {
            gray = t;
        }
        if (t.getColorModel().getColorSpace() == sRGB) {
            srgb = t;
        }
    }
    if (gray == null) {
        throw new RuntimeException("No gray type available.");
    }
    if (srgb == null) {
        throw new RuntimeException("No srgb type available.");
    }

    System.out.println("Read as GRAY...");
    testType(reader, gray, src);

    System.out.println("Read as sRGB...");
    testType(reader, srgb, src);
}
 
源代码5 项目: openjdk-jdk8u-backup   文件: ReadAsGrayTest.java
private static void doTest(int type) throws IOException {
    BufferedImage src = createTestImage(type);

    File f = new File("test.jpg");

    if (!ImageIO.write(src, "jpg", f)) {
        throw new RuntimeException("Failed to write test image.");
    }

    ImageInputStream iis = ImageIO.createImageInputStream(f);
    ImageReader reader = ImageIO.getImageReaders(iis).next();
    reader.setInput(iis);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    ImageTypeSpecifier srgb = null;
    ImageTypeSpecifier gray = null;
    // look for gray and srgb types
    while ((srgb == null || gray == null) && types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        if (t.getColorModel().getColorSpace().getType() == TYPE_GRAY) {
            gray = t;
        }
        if (t.getColorModel().getColorSpace() == sRGB) {
            srgb = t;
        }
    }
    if (gray == null) {
        throw new RuntimeException("No gray type available.");
    }
    if (srgb == null) {
        throw new RuntimeException("No srgb type available.");
    }

    System.out.println("Read as GRAY...");
    testType(reader, gray, src);

    System.out.println("Read as sRGB...");
    testType(reader, srgb, src);
}
 
源代码6 项目: openjdk-jdk9   文件: ReadAsGrayTest.java
private static void doTest(int type) throws IOException {
    BufferedImage src = createTestImage(type);

    File f = new File("test.jpg");

    if (!ImageIO.write(src, "jpg", f)) {
        throw new RuntimeException("Failed to write test image.");
    }

    ImageInputStream iis = ImageIO.createImageInputStream(f);
    ImageReader reader = ImageIO.getImageReaders(iis).next();
    reader.setInput(iis);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    ImageTypeSpecifier srgb = null;
    ImageTypeSpecifier gray = null;
    // look for gray and srgb types
    while ((srgb == null || gray == null) && types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        if (t.getColorModel().getColorSpace().getType() == TYPE_GRAY) {
            gray = t;
        }
        if (t.getColorModel().getColorSpace() == sRGB) {
            srgb = t;
        }
    }
    if (gray == null) {
        throw new RuntimeException("No gray type available.");
    }
    if (srgb == null) {
        throw new RuntimeException("No srgb type available.");
    }

    System.out.println("Read as GRAY...");
    testType(reader, gray, src);

    System.out.println("Read as sRGB...");
    testType(reader, srgb, src);
}
 
源代码7 项目: jdk8u-jdk   文件: ReadAsGrayTest.java
private static void doTest(int type) throws IOException {
    BufferedImage src = createTestImage(type);

    File f = new File("test.jpg");

    if (!ImageIO.write(src, "jpg", f)) {
        throw new RuntimeException("Failed to write test image.");
    }

    ImageInputStream iis = ImageIO.createImageInputStream(f);
    ImageReader reader = ImageIO.getImageReaders(iis).next();
    reader.setInput(iis);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    ImageTypeSpecifier srgb = null;
    ImageTypeSpecifier gray = null;
    // look for gray and srgb types
    while ((srgb == null || gray == null) && types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        if (t.getColorModel().getColorSpace().getType() == TYPE_GRAY) {
            gray = t;
        }
        if (t.getColorModel().getColorSpace() == sRGB) {
            srgb = t;
        }
    }
    if (gray == null) {
        throw new RuntimeException("No gray type available.");
    }
    if (srgb == null) {
        throw new RuntimeException("No srgb type available.");
    }

    System.out.println("Read as GRAY...");
    testType(reader, gray, src);

    System.out.println("Read as sRGB...");
    testType(reader, srgb, src);
}
 
源代码8 项目: hottub   文件: ReadAsGrayTest.java
private static void doTest(int type) throws IOException {
    BufferedImage src = createTestImage(type);

    File f = new File("test.jpg");

    if (!ImageIO.write(src, "jpg", f)) {
        throw new RuntimeException("Failed to write test image.");
    }

    ImageInputStream iis = ImageIO.createImageInputStream(f);
    ImageReader reader = ImageIO.getImageReaders(iis).next();
    reader.setInput(iis);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    ImageTypeSpecifier srgb = null;
    ImageTypeSpecifier gray = null;
    // look for gray and srgb types
    while ((srgb == null || gray == null) && types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        if (t.getColorModel().getColorSpace().getType() == TYPE_GRAY) {
            gray = t;
        }
        if (t.getColorModel().getColorSpace() == sRGB) {
            srgb = t;
        }
    }
    if (gray == null) {
        throw new RuntimeException("No gray type available.");
    }
    if (srgb == null) {
        throw new RuntimeException("No srgb type available.");
    }

    System.out.println("Read as GRAY...");
    testType(reader, gray, src);

    System.out.println("Read as sRGB...");
    testType(reader, srgb, src);
}
 
源代码9 项目: openjdk-8-source   文件: ReadAsGrayTest.java
private static void doTest(int type) throws IOException {
    BufferedImage src = createTestImage(type);

    File f = new File("test.jpg");

    if (!ImageIO.write(src, "jpg", f)) {
        throw new RuntimeException("Failed to write test image.");
    }

    ImageInputStream iis = ImageIO.createImageInputStream(f);
    ImageReader reader = ImageIO.getImageReaders(iis).next();
    reader.setInput(iis);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    ImageTypeSpecifier srgb = null;
    ImageTypeSpecifier gray = null;
    // look for gray and srgb types
    while ((srgb == null || gray == null) && types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        if (t.getColorModel().getColorSpace().getType() == TYPE_GRAY) {
            gray = t;
        }
        if (t.getColorModel().getColorSpace() == sRGB) {
            srgb = t;
        }
    }
    if (gray == null) {
        throw new RuntimeException("No gray type available.");
    }
    if (srgb == null) {
        throw new RuntimeException("No srgb type available.");
    }

    System.out.println("Read as GRAY...");
    testType(reader, gray, src);

    System.out.println("Read as sRGB...");
    testType(reader, srgb, src);
}
 
源代码10 项目: openjdk-8   文件: ReadAsGrayTest.java
private static void doTest(int type) throws IOException {
    BufferedImage src = createTestImage(type);

    File f = new File("test.jpg");

    if (!ImageIO.write(src, "jpg", f)) {
        throw new RuntimeException("Failed to write test image.");
    }

    ImageInputStream iis = ImageIO.createImageInputStream(f);
    ImageReader reader = ImageIO.getImageReaders(iis).next();
    reader.setInput(iis);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    ImageTypeSpecifier srgb = null;
    ImageTypeSpecifier gray = null;
    // look for gray and srgb types
    while ((srgb == null || gray == null) && types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        if (t.getColorModel().getColorSpace().getType() == TYPE_GRAY) {
            gray = t;
        }
        if (t.getColorModel().getColorSpace() == sRGB) {
            srgb = t;
        }
    }
    if (gray == null) {
        throw new RuntimeException("No gray type available.");
    }
    if (srgb == null) {
        throw new RuntimeException("No srgb type available.");
    }

    System.out.println("Read as GRAY...");
    testType(reader, gray, src);

    System.out.println("Read as sRGB...");
    testType(reader, srgb, src);
}
 
源代码11 项目: jdk8u_jdk   文件: ReadAsGrayTest.java
private static void doTest(int type) throws IOException {
    BufferedImage src = createTestImage(type);

    File f = new File("test.jpg");

    if (!ImageIO.write(src, "jpg", f)) {
        throw new RuntimeException("Failed to write test image.");
    }

    ImageInputStream iis = ImageIO.createImageInputStream(f);
    ImageReader reader = ImageIO.getImageReaders(iis).next();
    reader.setInput(iis);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    ImageTypeSpecifier srgb = null;
    ImageTypeSpecifier gray = null;
    // look for gray and srgb types
    while ((srgb == null || gray == null) && types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        if (t.getColorModel().getColorSpace().getType() == TYPE_GRAY) {
            gray = t;
        }
        if (t.getColorModel().getColorSpace() == sRGB) {
            srgb = t;
        }
    }
    if (gray == null) {
        throw new RuntimeException("No gray type available.");
    }
    if (srgb == null) {
        throw new RuntimeException("No srgb type available.");
    }

    System.out.println("Read as GRAY...");
    testType(reader, gray, src);

    System.out.println("Read as sRGB...");
    testType(reader, srgb, src);
}
 
源代码12 项目: jdk8u-jdk   文件: ReadAsGrayTest.java
private static void doTest(int type) throws IOException {
    BufferedImage src = createTestImage(type);

    File f = new File("test.jpg");

    if (!ImageIO.write(src, "jpg", f)) {
        throw new RuntimeException("Failed to write test image.");
    }

    ImageInputStream iis = ImageIO.createImageInputStream(f);
    ImageReader reader = ImageIO.getImageReaders(iis).next();
    reader.setInput(iis);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    ImageTypeSpecifier srgb = null;
    ImageTypeSpecifier gray = null;
    // look for gray and srgb types
    while ((srgb == null || gray == null) && types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        if (t.getColorModel().getColorSpace().getType() == TYPE_GRAY) {
            gray = t;
        }
        if (t.getColorModel().getColorSpace() == sRGB) {
            srgb = t;
        }
    }
    if (gray == null) {
        throw new RuntimeException("No gray type available.");
    }
    if (srgb == null) {
        throw new RuntimeException("No srgb type available.");
    }

    System.out.println("Read as GRAY...");
    testType(reader, gray, src);

    System.out.println("Read as sRGB...");
    testType(reader, srgb, src);
}
 
源代码13 项目: jdk8u-dev-jdk   文件: ReadAsGrayTest.java
private static void doTest(int type) throws IOException {
    BufferedImage src = createTestImage(type);

    File f = new File("test.jpg");

    if (!ImageIO.write(src, "jpg", f)) {
        throw new RuntimeException("Failed to write test image.");
    }

    ImageInputStream iis = ImageIO.createImageInputStream(f);
    ImageReader reader = ImageIO.getImageReaders(iis).next();
    reader.setInput(iis);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    ImageTypeSpecifier srgb = null;
    ImageTypeSpecifier gray = null;
    // look for gray and srgb types
    while ((srgb == null || gray == null) && types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        if (t.getColorModel().getColorSpace().getType() == TYPE_GRAY) {
            gray = t;
        }
        if (t.getColorModel().getColorSpace() == sRGB) {
            srgb = t;
        }
    }
    if (gray == null) {
        throw new RuntimeException("No gray type available.");
    }
    if (srgb == null) {
        throw new RuntimeException("No srgb type available.");
    }

    System.out.println("Read as GRAY...");
    testType(reader, gray, src);

    System.out.println("Read as sRGB...");
    testType(reader, srgb, src);
}
 
源代码14 项目: sejda   文件: PageImageWriter.java
/**
 * Checks if the input file is a PNG using ICC Gray color model
 * If that's the case, converts to RGB and returns the file path
 */
private static Optional<SeekableSource> convertICCGrayPngIf(SeekableSource source) throws IOException, TaskIOException {
    try {
        if (FileType.PNG.equals(getFileType(source))) {
            try (ImageInputStream iis = ImageIO.createImageInputStream(source.asNewInputStream())) {
                ImageReader reader = ImageIO.getImageReadersByFormatName("png").next();
                boolean isICCGray = false;
                try {
                    ImageIO.setUseCache(false);
                    reader.setInput(iis);
                    for (Iterator<ImageTypeSpecifier> it = reader.getImageTypes(0); it.hasNext(); ) {
                        ImageTypeSpecifier typeSpecifier = it.next();
                        ColorSpace colorSpace = typeSpecifier.getColorModel().getColorSpace();
                        if (colorSpace instanceof ICC_ColorSpace && ((ICC_ColorSpace) colorSpace).getProfile() instanceof ICC_ProfileGray) {
                            isICCGray = true;
                            break;
                        }
                    }

                    if (isICCGray) {
                        LOG.debug("Detected a Gray PNG image, will convert to RGB and save to a new file");
                        // convert to rgb
                        BufferedImage original = reader.read(0);
                        BufferedImage rgb = toARGB(original);
                        File tmpFile = IOUtils.createTemporaryBuffer();
                        ImageIO.write(rgb, "png", tmpFile);
                        return Optional.of(SeekableSources.seekableSourceFrom(tmpFile));
                    }
                } finally {
                    reader.dispose();
                }
            }
        }
    } catch (IIOException e) {
        LOG.debug("Failed convertICCGrayPngIf()", e);
    }

    return Optional.empty();
}
 
源代码15 项目: dss   文件: ImageUtils.java
private static boolean isSupportedColorSpace(ImageReader reader) throws IOException {
	Iterator<ImageTypeSpecifier> imageTypes = reader.getImageTypes(0);
	// ImageReader detects only processable types
	return imageTypes.hasNext();
}
 
源代码16 项目: sejda   文件: PageImageWriter.java
/**
 * Checks if the input file is a JPEG using CMYK
 * If that's the case, converts to RGB and returns the file path
 */
private static Optional<SeekableSource> convertCMYKJpegIf(SeekableSource source) throws IOException, TaskIOException {
    try {
        if (FileType.JPEG.equals(getFileType(source))) {
            try (ImageInputStream iis = ImageIO.createImageInputStream(source.asNewInputStream())) {
                ImageReader reader = ImageIO.getImageReadersByFormatName("jpg").next();
                boolean isCmyk = false;
                try {
                    ImageIO.setUseCache(false);
                    reader.setInput(iis);
                    for (Iterator<ImageTypeSpecifier> it = reader.getImageTypes(0); it.hasNext(); ) {
                        ImageTypeSpecifier typeSpecifier = it.next();
                        if (typeSpecifier.getColorModel().getColorSpace().getType() == ColorSpace.TYPE_CMYK) {
                            isCmyk = true;
                        }
                    }

                    if (isCmyk) {
                        LOG.debug("Detected a CMYK JPEG image, will convert to RGB and save to a new file");
                        // convert to rgb
                        // twelvemonkeys JPEG plugin already converts it to rgb when reading the image
                        // just write it out
                        BufferedImage image = reader.read(0);
                        File tmpFile = IOUtils.createTemporaryBuffer();
                        ImageIO.write(image, "jpg", tmpFile);
                        return Optional.of(SeekableSources.seekableSourceFrom(tmpFile));
                    }
                } finally {
                    reader.dispose();
                }
            }
        }
    } catch (IIOException e) {
        if(e.getMessage().startsWith("Not a JPEG stream")) {
            // this was a different image format with a JPEG extension
        } else {
            throw e;
        }
    }

    return Optional.empty();
}