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


Java ImageInputStream.reset方法代码示例

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


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

示例1: canDecodeInput

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
public boolean canDecodeInput(Object input) throws IOException {
    if (!(input instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)input;
    byte[] b = new byte[8];
    stream.mark();
    stream.readFully(b);
    stream.reset();

    return (b[0] == (byte)137 &&
            b[1] == (byte)80 &&
            b[2] == (byte)78 &&
            b[3] == (byte)71 &&
            b[4] == (byte)13 &&
            b[5] == (byte)10 &&
            b[6] == (byte)26 &&
            b[7] == (byte)10);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:RegisterPluginTwiceTest.java

示例2: canDecodeInput

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof ImageInputStream)) {
        return false;
    }
    ImageInputStream iis = (ImageInputStream) source;
    iis.mark();
    // If the first two bytes are a JPEG SOI marker, it's probably
    // a JPEG file.  If they aren't, it definitely isn't a JPEG file.
    int byte1 = iis.read();
    int byte2 = iis.read();
    iis.reset();
    if ((byte1 == 0xFF) && (byte2 == JPEG.SOI)) {
        return true;
    }
    return false;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:JPEGImageReaderSpi.java

示例3: getThumbnail

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    DataBufferByte buffer = new DataBufferByte(getLength());
    readByteBuffer(iis,
                   buffer.getData(),
                   reader,
                   1.0F,
                   0.0F);
    iis.reset();

    WritableRaster raster =
        Raster.createInterleavedRaster(buffer,
                                       thumbWidth,
                                       thumbHeight,
                                       thumbWidth*3,
                                       3,
                                       new int [] {0, 1, 2},
                                       null);
    ColorModel cm = new ComponentColorModel(JPEG.JCS.sRGB,
                                            false,
                                            false,
                                            ColorModel.OPAQUE,
                                            DataBuffer.TYPE_BYTE);
    return new BufferedImage(cm,
                             raster,
                             false,
                             null);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:32,代码来源:JFIFMarkerSegment.java

示例4: canDecodeInput

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof ImageInputStream)) {
        return false;
    }
    ImageInputStream stream = (ImageInputStream)source;

    stream.mark();
    try {
         byte[] sig = new byte[4];
         stream.read(sig);
         return sig[0]=='S' && sig[1]=='I' && sig[2]=='M' && sig[3]=='P';
    } finally {
        stream.reset();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:SIMPImageReaderSpi.java

示例5: canDecodeInput

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
public boolean canDecodeInput(Object input) throws IOException {
    if (!(input instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)input;
    byte[] b = new byte[6];
    stream.mark();
    stream.readFully(b);
    stream.reset();

    return b[0] == 'G' && b[1] == 'I' && b[2] == 'F' && b[3] == '8' &&
        (b[4] == '7' || b[4] == '9') && b[5] == 'a';
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:15,代码来源:GIFImageReaderSpi.java

示例6: canDecodeInput

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)source;
    byte[] b = new byte[2];
    stream.mark();
    stream.readFully(b);
    stream.reset();

    return (b[0] == 0x42) && (b[1] == 0x4d);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:BMPImageReaderSpi.java

示例7: canDecodeInput

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)source;

    stream.mark();
    try {
        int type = stream.readByte();   // TypeField
        int fixHeaderField = stream.readByte();
        // check WBMP "header"
        if (type != 0 || fixHeaderField != 0) {
            // while WBMP reader does not support ext WBMP headers
            return false;
        }

        int width = ReaderUtil.readMultiByteInteger(stream);
        int height = ReaderUtil.readMultiByteInteger(stream);
        // check image dimension
        if (width <= 0 || height <= 0) {
            return false;
        }

        long dataLength = stream.length();
        if (dataLength == -1) {
            // We can't verify that amount of data in the stream
            // corresponds to image dimension because we do not know
            // the length of the data stream.
            // Assuming that wbmp image are used for mobile devices,
            // let's introduce an upper limit for image dimension.
            // In case if exact amount of raster data is unknown,
            // let's reject images with dimension above the limit.
            return (width < MAX_WBMP_WIDTH) && (height < MAX_WBMP_HEIGHT);
        }

        dataLength -= stream.getStreamPosition();

        long scanSize = (width / 8) + ((width % 8) == 0 ? 0 : 1);

        return (dataLength == scanSize * height);
    } finally {
        stream.reset();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:46,代码来源:WBMPImageReaderSpi.java

示例8: test

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
private static void test() throws IOException {
    int failures = 0;

    for (int imageType : typeToCompression.keySet()) {
        BufferedImage image = new BufferedImage(WIDTH, HEIGHT, imageType);
        System.out.println("Image: " + image.toString());

        for (String compression : typeToCompression.get(imageType)) {
            System.out.println("Compression: "
                    + (compression == null ? "None" : compression));
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            ImageOutputStream ios = new MemoryCacheImageOutputStream(output);
            ImageWriter writer =
                    ImageIO.getImageWritersByFormatName("TIFF").next();
            ImageWriteParam wparam = writer.getDefaultWriteParam();
            if (compression == null) {
                wparam.setCompressionMode(ImageWriteParam.MODE_DEFAULT);
            } else {
                wparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                wparam.setCompressionType(compression);
            }
            writer.setOutput(ios);
            writer.write(null, new IIOImage(image, null, null), wparam);
            ios.flush();

            ImageReader reader =
                    ImageIO.getImageReadersByFormatName("TIFF").next();
            ByteArrayInputStream input
                    = new ByteArrayInputStream(output.toByteArray());
            ImageInputStream iis = new MemoryCacheImageInputStream(input);
            iis.mark();

            TIFFImageReadParam rparam = new TIFFImageReadParam();
            rparam.removeAllowedTagSet(BaselineTIFFTagSet.getInstance());

            reader.setInput(iis, false, false);
            BufferedImage resultFalse = reader.read(0, rparam);
            if (resultFalse.getWidth() != WIDTH
                    || resultFalse.getHeight() != HEIGHT) {
                System.err.printf("Read image dimensions != %d x %d%n",
                        WIDTH, HEIGHT);
                failures++;
            } else {
                System.out.println("ignoreMetadata == false test passed");
            }

            iis.reset();
            reader.setInput(iis, false, true);
            BufferedImage resultTrue;
            try {
                resultTrue = reader.read(0, rparam);
                if (resultTrue.getWidth() != WIDTH
                        || resultTrue.getHeight() != HEIGHT) {
                    System.err.printf("Read image dimensions != %d x %d%n",
                            WIDTH, HEIGHT);
                    failures++;
                } else {
                    System.out.println("ignoreMetadata == true test passed");
                }
            } catch (Exception e) {
                e.printStackTrace();
                failures++;
            }
        }
    }

    if (failures != 0) {
        throw new RuntimeException("Test failed with "
                + failures + " errors!");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:72,代码来源:ReadWithoutBaselineTagSet.java


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