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


Java ImageInputStream.readBits方法代码示例

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


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

示例1: reformatDiscontiguousData

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
/**
 * Reformats bit-discontiguous data into the {@code DataBuffer}
 * of the supplied {@code WritableRaster}.
 */
private static void reformatDiscontiguousData(byte[] buf,
                                              int[] bitsPerSample,
                                              int stride,
                                              int w,
                                              int h,
                                              WritableRaster raster)
    throws IOException {

    // Get SampleModel info.
    SampleModel sm = raster.getSampleModel();
    int numBands = sm.getNumBands();

    // Initialize input stream.
    ByteArrayInputStream is = new ByteArrayInputStream(buf);
    ImageInputStream iis = new MemoryCacheImageInputStream(is);

    // Reformat.
    long iisPosition = 0L;
    int y = raster.getMinY();
    for(int j = 0; j < h; j++, y++) {
        iis.seek(iisPosition);
        int x = raster.getMinX();
        for(int i = 0; i < w; i++, x++) {
            for(int b = 0; b < numBands; b++) {
                long bits = iis.readBits(bitsPerSample[b]);
                raster.setSample(x, y, b, (int)bits);
            }
        }
        iisPosition += stride;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:TIFFDecompressor.java

示例2: main

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    byte[] buffer = new byte[] {(byte)169, (byte)85}; // 10101001 01010101
    InputStream ins = new ByteArrayInputStream(buffer);
    ImageInputStream in = new FileCacheImageInputStream(ins,null);

    if (in.getBitOffset() != 0) {
        throw new RuntimeException("Initial bit offset != 0!");
    }

    int bit0 = in.readBit(); // 1
    if (bit0 != 1) {
        throw new RuntimeException("First bit != 1");
    }
    if (in.getBitOffset() != 1) {
        throw new RuntimeException("Second bit offset != 1");
    }

    long bits1 = in.readBits(5); // 01010 = 10
    if (bits1 != 10) {
        throw new RuntimeException("Bits 1-5 != 10 (= " + bits1 + ")");
    }
    if (in.getBitOffset() != 6) {
        throw new RuntimeException("Third bit offset != 6");
    }

    int bit1 = in.readBit(); // 0
    if (bit1 != 0) {
        throw new RuntimeException("Bit 6 != 0");
    }
    if (in.getBitOffset() != 7) {
        throw new RuntimeException("Third bit offset != 7");
    }

    long bits2 = in.readBits(8); // 10101010 = 170
    if (bits2 != 170) {
        throw new RuntimeException("Bits 7-14 != 170 (= " + bits2 + ")");
    }
    if (in.getBitOffset() != 7) {
        throw new RuntimeException("Fourth bit offset != 7");
    }

    int bit2 = in.readBit(); // 1
    if (bit2 != 1) {
        throw new RuntimeException("Bit 15 != 1");
    }
    if (in.getBitOffset() != 0) {
        throw new RuntimeException("Fifth bit offset != 0");
    }

    in.close();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:52,代码来源:ReadBitsTest.java


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