PCXReader.java 文件源码

java
阅读 19 收藏 0 点赞 0 评论 0

项目:icafe 作者:
private BufferedImage readTrueColorPcx(InputStream is) throws Exception {
    byte brgb[] = IOUtils.readFully(is, 4096);
    byte pixels[] = new byte[bytesPerLine*NPlanes*height];

    /**
     * A BufferedInputStream could have been constructed from the InputStream,
     * but for maximum decoding speed, one time reading of the image data 
     * into memory is ideal though this is memory consuming.
     */
    LOGGER.info("true color pcx image!");

    readScanLines(brgb, brgb.length, pixels);
    is.close();

 DataBuffer db = new DataBufferByte(pixels, pixels.length);
 int trans = Transparency.OPAQUE;
 int[] nBits = {8, 8, 8};                       
 WritableRaster raster = Raster.createBandedRaster(db, width, height, bytesPerLine*3,
            new int[]{0, 0, 0}, new int[] {0, bytesPerLine, bytesPerLine*2}, null);
 ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), nBits, false, false,
            trans, DataBuffer.TYPE_BYTE);

 return new BufferedImage(cm, raster, false, null);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号