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


Java PngChunkTRNS.setIndexEntryAsTransparent方法代码示例

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


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

示例1: encodeIndexedPNG

import ar.com.hjg.pngj.chunks.PngChunkTRNS; //导入方法依赖的package包/类
public byte [] encodeIndexedPNG (int [] pixels, int width, int height, boolean color, int bits) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    int [] palette = getPalette();

    boolean alpha = Color.alpha(palette[0]) == 0;
    boolean grayscale = !color;
    //Log.d(TAG, "encodeIndexedPNG: color = "+color +", alpha ="+alpha+", grayscale = "+grayscale);

    //ImageInfo imageInfo = new ImageInfo(width, height, bits, alpha, grayscale, color);
    ImageInfo imageInfo = new ImageInfo(width, height, bits, false, grayscale, color);
    PngWriter writer = new PngWriter(bos, imageInfo);
    writer.getPixelsWriter().setDeflaterCompLevel(9);

    if (color) {
        PngChunkPLTE paletteChunk = writer.getMetadata().createPLTEChunk();
        paletteChunk.setNentries(palette.length);

        for (int i = 0; i < palette.length; i++) {
            int c = palette[i];
            paletteChunk.setEntry(i, Color.red(c), Color.green(c), Color.blue(c));
        }
    }

    if (alpha) {
        PngChunkTRNS trnsChunk = writer.getMetadata().createTRNSChunk();
        if (color) {
            trnsChunk.setIndexEntryAsTransparent(0);
        } else {
            trnsChunk.setGray(1);
        }
    }
    else {
        quantize(pixels, imageInfo.cols);
    }
    ImageLineInt line = new ImageLineInt(imageInfo);
    for (int y = 0; y < imageInfo.rows; y++) {
        int [] lineData = line.getScanline();
        for (int x = 0; x < imageInfo.cols; x++) {
            int pixel = pixels[y * imageInfo.cols + x];
            //lineData[x] = getNearestColorIndex(pixel) ^ (x % 2) ^ (y % 2);
            lineData[x] = getNearestColorIndex(pixel);
        }
        writer.writeRow(line);
    }

    writer.end();
    return bos.toByteArray();
}
 
开发者ID:NightscoutFoundation,项目名称:xDrip,代码行数:50,代码来源:SimpleImageEncoder.java

示例2: encodeIndexedPNG

import ar.com.hjg.pngj.chunks.PngChunkTRNS; //导入方法依赖的package包/类
public byte [] encodeIndexedPNG (int [] pixels, int width, int height, boolean color, int bits) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    int [] palette = getPalette();

    boolean alpha = Color.alpha(palette[0]) == 0;
    boolean grayscale = !color;
    //Log.d(TAG, "encodeIndexedPNG: color = "+color +", alpha ="+alpha+", grayscale = "+grayscale);

    //ImageInfo imageInfo = new ImageInfo(width, height, bits, alpha, grayscale, color);
    ImageInfo imageInfo = new ImageInfo(width, height, bits, false, grayscale, color);
    PngWriter writer = new PngWriter(bos, imageInfo);
    writer.getPixelsWriter().setDeflaterCompLevel(9);

    if (color) {
        PngChunkPLTE paletteChunk = writer.getMetadata().createPLTEChunk();
        paletteChunk.setNentries(palette.length);

        for (int i = 0; i < palette.length; i++) {
            int c = palette[i];
            paletteChunk.setEntry(i, Color.red(c), Color.green(c), Color.blue(c));
        }
    }

    if (alpha) {
        PngChunkTRNS trnsChunk = writer.getMetadata().createTRNSChunk();
        if (color) {
            trnsChunk.setIndexEntryAsTransparent(0);
        } else {
            trnsChunk.setGray(1);
        }
    }
    else {
        quantize(pixels, imageInfo.cols);
    }
    ImageLineInt line = new ImageLineInt(imageInfo);
    for (int y = 0; y < imageInfo.rows; y++) {
        int [] lineData = line.getScanline();
        for (int x = 0; x < imageInfo.cols; x++) {
            int pixel = pixels[y * imageInfo.cols + x];

            lineData[x] = getNearestColorIndex(pixel);
        }
        writer.writeRow(line);
    }

    writer.end();
    return bos.toByteArray();
}
 
开发者ID:StephenBlackWasAlreadyTaken,项目名称:xDrip-Experimental,代码行数:50,代码来源:SimpleImageEncoder.java


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