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


Java ImageInfo类代码示例

本文整理汇总了Java中ar.com.hjg.pngj.ImageInfo的典型用法代码示例。如果您正苦于以下问题:Java ImageInfo类的具体用法?Java ImageInfo怎么用?Java ImageInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: writeMaskedTwoBitPng

import ar.com.hjg.pngj.ImageInfo; //导入依赖的package包/类
public static void writeMaskedTwoBitPng(Bitmap blackAndWhiteBitmap, OutputStream stream, boolean transparentBlack)
{
    LightBitmap lightBitmap = new LightBitmap(blackAndWhiteBitmap);
    ImageInfo imageInfo = new ImageInfo(lightBitmap.getWidth(), lightBitmap.getHeight(), 1, false, true, false);
    PngWriter pngWriter = new PngWriter(stream, imageInfo);

    PngChunkTRNS transparencyChunk = pngWriter.getMetadata().createTRNSChunk();
    transparencyChunk.setGray(transparentBlack ? 0 : 1);

    for (int y = 0; y < lightBitmap.getHeight(); y++)
    {
        ImageLineByte imageLine = new ImageLineByte(imageInfo);
        for (int x = 0; x < lightBitmap.getWidth(); x++)
        {
            int pixel = lightBitmap.getPixel(x, y) & 0x00FFFFFF;
            int r = Color.red(pixel);

            imageLine.getScanline()[x] = (byte) (r > 255 / 2 ? 1 : 0);
        }

        pngWriter.writeRow(imageLine, y);
    }

    pngWriter.end();
}
 
开发者ID:matejdro,项目名称:PebbleAndroidCommons,代码行数:26,代码来源:PebbleImageToolkit.java

示例2: createMap

import ar.com.hjg.pngj.ImageInfo; //导入依赖的package包/类
public static void createMap(MapScript script) {
    PngWriter map = new PngWriter(createRelativeFile(script.getOutputFile()), new ImageInfo(script.getWidth(), script.getHeight(), 8, false));
    map.setShouldCloseStream(true);
    System.out.println("Initializing overlays...");
    MapOverlay.initOverlays(script);
    System.out.println("Initializing scaler...");
    MapScaler.initScaler(script, map.imgInfo);
    System.out.println("Initializing importer...");
    MapImporter.initConverter();
    System.out.println("Initializing exporter...");
    MapExporter.init(script.getExports());
    System.out.println("Creating map...");
    MapMerger.mergeTiles(script, map);
    System.out.println("Saving map...");
    MapScaler.saveScaler();
    map.end();
}
 
开发者ID:warriordog,项目名称:MapMaster,代码行数:18,代码来源:MapMaster.java

示例3: writePngImage

import ar.com.hjg.pngj.ImageInfo; //导入依赖的package包/类
/**
     * Writes a {@link BufferedImage} to the specified {@link OutputStream} using the PNGJ library
     * which is much faster than Java's ImageIO library.
     *
     * This implementation was copied from
     * <a href="https://github.com/leonbloy/pngj/wiki/Snippets">
     *     https://github.com/leonbloy/pngj/wiki/Snippets
     * </a>.
     *
     * @param  bufferedImage     image to write.
     * @param  compressionLevel  0 (no compression) - 9 (max compression)
     * @param  filterType        internal prediction filter type.
     * @param  outputStream      target stream.
     *
     * @throws IOException
     *   if the image is not ARGB or it's data buffer contains the wrong number of banks.
     */
    public static void writePngImage(final BufferedImage bufferedImage,
                                     final int compressionLevel,
                                     final FilterType filterType,
                                     final OutputStream outputStream)
            throws IOException {

        if (bufferedImage.getType() != BufferedImage.TYPE_INT_ARGB) {
            throw new IOException("invalid image type (" + bufferedImage.getType() +
                                  "), must be BufferedImage.TYPE_INT_ARGB");
        }

        final ImageInfo imageInfo = new ImageInfo(bufferedImage.getWidth(), bufferedImage.getHeight(), 8, true);

        final PngWriter pngWriter = new PngWriter(outputStream, imageInfo);
        pngWriter.setCompLevel(compressionLevel);
        pngWriter.setFilterType(filterType);

        final DataBufferInt dataBuffer =((DataBufferInt) bufferedImage.getRaster().getDataBuffer());
        if (dataBuffer.getNumBanks() != 1) {
            throw new IOException("invalid number of banks (" + dataBuffer.getNumBanks() + "), must be 1");
        }

        final SinglePixelPackedSampleModel sampleModel = (SinglePixelPackedSampleModel) bufferedImage.getSampleModel();
        final ImageLineInt line = new ImageLineInt(imageInfo);
        final int[] data = dataBuffer.getData();
        for (int row = 0; row < imageInfo.rows; row++) {
            int elem = sampleModel.getOffset(0, row);
            for (int col = 0; col < imageInfo.cols; col++) {
                final int sample = data[elem++];
                ImageLineHelper.setPixelRGBA8(line, col, sample);
            }
            pngWriter.writeRow(line, row);
        }
        pngWriter.end();

//        // This looked like a nicer option, but only works for DataBufferByte (not DataBufferInt)
//        final ImageLineSetARGBbi lines = new ImageLineSetARGBbi(bufferedImage, imageInfo);
//        pngWriter.writeRows(lines);
//        pngWriter.end();
    }
 
开发者ID:saalfeldlab,项目名称:render,代码行数:58,代码来源:BufferedImageStreamingOutput.java

示例4: fillFromInfo

import ar.com.hjg.pngj.ImageInfo; //导入依赖的package包/类
public void fillFromInfo(ImageInfo info) {
    setCols(imgInfo.cols);
    setRows(imgInfo.rows);
    setBitspc(imgInfo.bitDepth);
    int colormodel = 0;
    if (imgInfo.alpha)
        colormodel += 0x04;
    if (imgInfo.indexed)
        colormodel += 0x01;
    if (!imgInfo.greyscale)
        colormodel += 0x02;
    setColormodel(colormodel);
    setCompmeth(0); // compression method 0=deflate
    setFilmeth(0); // filter method (0)
    setInterlaced(0); // we never interlace
}
 
开发者ID:4142,项目名称:audio2png,代码行数:17,代码来源:PngChunkIHDR.java

示例5: prepareGraphics

import ar.com.hjg.pngj.ImageInfo; //导入依赖的package包/类
/**
 * Makes array of either null (if maps[n] is false) or a new PngWriter
 */
public static PngWriter[] prepareGraphics(int size, File folder, boolean[] maps)
{
    PngWriter[] out = new PngWriter[Layers.values().length];
    for (int i = 0; i < out.length; i++) if (maps[i]) out[i] = new PngWriter(new File(folder, Layers.values()[i].name().toLowerCase() + ".png"), new ImageInfo(size, size, 8, false), true);
    return out;
}
 
开发者ID:dries007,项目名称:TFCSeedMaker,代码行数:10,代码来源:Helper.java

示例6: ElevationPngImage

import ar.com.hjg.pngj.ImageInfo; //导入依赖的package包/类
/**
 * Constructor, used for writing a PNG
 *
 * @param imageInfo
 */
public ElevationPngImage(ImageInfo imageInfo) {
    outputStream = new ByteArrayOutputStream();
    writer = new PngWriter(outputStream, imageInfo);
    width = imageInfo.cols;
    height = imageInfo.rows;
}
 
开发者ID:ngageoint,项目名称:geopackage-android,代码行数:12,代码来源:ElevationPngImage.java

示例7: convertToPNG

import ar.com.hjg.pngj.ImageInfo; //导入依赖的package包/类
public void convertToPNG(Dds dds, OutputStream outputStream, String swizzle) throws IOException {
    DdsHeader header = dds.getHeader();
    FormatDecoder decoder = Decoders.getDecoder(dds);
    ImageInfo imageInfo = new ImageInfo(header.getDwWidth(), header.getDwHeight(), 8, true);
    PngWriter pngWriter = new PngWriter(outputStream, imageInfo);
    ImageLineInt imageLine = new ImageLineInt(imageInfo);
    for (int[] ints : decoder) {
        swizzle(ints, swizzle);
        ImageLineHelper.setPixelsRGBA8(imageLine, ints);
        pngWriter.writeRow(imageLine);
    }

    pngWriter.end();
}
 
开发者ID:vincentzhang96,项目名称:DDS4J,代码行数:15,代码来源:DdsImageDecoder.java

示例8: initScaler

import ar.com.hjg.pngj.ImageInfo; //导入依赖的package包/类
public static void initScaler(MapScript script, ImageInfo fullInf) {
    int numScales = script.getNumScales() - 1;
    if (numScales > 0) {
        writers = new TrackedPngWriter[numScales];
        for (int index = 0; index < numScales; index++) {
            int scale = (int) Math.pow(2, index + 1);
            ImageInfo inf = new ImageInfo(fullInf.cols / scale, fullInf.rows / scale, fullInf.bitDepth, fullInf.alpha);
            TrackedPngWriter writer = new TrackedPngWriter(getScaleFile(script, index), inf);
            writers[index] = writer;
        }
    }
}
 
开发者ID:warriordog,项目名称:MapMaster,代码行数:13,代码来源:MapScaler.java

示例9: PixelsWriterMultiple

import ar.com.hjg.pngj.ImageInfo; //导入依赖的package包/类
public PixelsWriterMultiple(ImageInfo imgInfo) {
    super(imgInfo);
    filtersPerf = new FiltersPerformance(imgInfo);
    rows = new LinkedList<byte[]>();
    for (int i = 0; i < 2; i++)
        rows.add(new byte[buflen]); // we preallocate 2 rows (rowb and rowbprev)
    filteredRowTmp = new byte[buflen];
}
 
开发者ID:4142,项目名称:audio2png,代码行数:9,代码来源:PixelsWriterMultiple.java

示例10: PngChunk

import ar.com.hjg.pngj.ImageInfo; //导入依赖的package包/类
public PngChunk(String id, ImageInfo imgInfo) {
    this.id = id;
    this.imgInfo = imgInfo;
    this.crit = ChunkHelper.isCritical(id);
    this.pub = ChunkHelper.isPublic(id);
    this.safe = ChunkHelper.isSafeToCopy(id);
}
 
开发者ID:4142,项目名称:audio2png,代码行数:8,代码来源:PngChunk.java

示例11: createImageInfo

import ar.com.hjg.pngj.ImageInfo; //导入依赖的package包/类
/**
 * throws PngInputException if unexpected values
 */
public ImageInfo createImageInfo() {
    check();
    boolean alpha = (getColormodel() & 0x04) != 0;
    boolean palette = (getColormodel() & 0x01) != 0;
    boolean grayscale = (getColormodel() == 0 || getColormodel() == 4);
    // creates ImgInfo and imgLine, and allocates buffers
    return new ImageInfo(getCols(), getRows(), getBitspc(), alpha, grayscale, palette);
}
 
开发者ID:4142,项目名称:audio2png,代码行数:12,代码来源:PngChunkIHDR.java

示例12: createChunk

import ar.com.hjg.pngj.ImageInfo; //导入依赖的package包/类
public final PngChunk createChunk(ChunkRaw chunkRaw, ImageInfo imgInfo) {
    PngChunk c = createEmptyChunkKnown(chunkRaw.id, imgInfo);
    if (c == null)
        c = createEmptyChunkExtended(chunkRaw.id, imgInfo);
    if (c == null)
        c = createEmptyChunkUnknown(chunkRaw.id, imgInfo);
    c.setRaw(chunkRaw);
    if (parse && chunkRaw.data != null)
        c.parseFromRaw(chunkRaw);
    return c;
}
 
开发者ID:4142,项目名称:audio2png,代码行数:12,代码来源:ChunkFactory.java

示例13: createPredicate

import ar.com.hjg.pngj.ImageInfo; //导入依赖的package包/类
/**
 * Creates a predicate equivalent to the copy mask
 * <p/>
 * Given a copy mask (see static fields) and the ImageInfo of the target PNG, returns a predicate that tells if a
 * chunk should be copied.
 * <p/>
 * This is a handy helper method, you can also create and set your own predicate
 */
public static ChunkPredicate createPredicate(final int copyFromMask, final ImageInfo imgInfo) {
    return new ChunkPredicate() {
        public boolean match(PngChunk chunk) {
            if (chunk.crit) {
                if (chunk.id.equals(ChunkHelper.PLTE)) {
                    if (imgInfo.indexed && maskMatch(copyFromMask, ChunkCopyBehaviour.COPY_PALETTE))
                        return true;
                    if (!imgInfo.greyscale && maskMatch(copyFromMask, ChunkCopyBehaviour.COPY_ALL))
                        return true;
                }
            } else { // ancillary
                boolean text = (chunk instanceof PngChunkTextVar);
                boolean safe = chunk.safe;
                // notice that these if are not exclusive
                if (maskMatch(copyFromMask, ChunkCopyBehaviour.COPY_ALL))
                    return true;
                if (safe && maskMatch(copyFromMask, ChunkCopyBehaviour.COPY_ALL_SAFE))
                    return true;
                if (chunk.id.equals(ChunkHelper.tRNS)
                        && maskMatch(copyFromMask, ChunkCopyBehaviour.COPY_TRANSPARENCY))
                    return true;
                if (chunk.id.equals(ChunkHelper.pHYs)
                        && maskMatch(copyFromMask, ChunkCopyBehaviour.COPY_PHYS))
                    return true;
                if (text && maskMatch(copyFromMask, ChunkCopyBehaviour.COPY_TEXTUAL))
                    return true;
                if (maskMatch(copyFromMask, ChunkCopyBehaviour.COPY_ALMOSTALL)
                        && !(ChunkHelper.isUnknown(chunk) || text || chunk.id.equals(ChunkHelper.hIST) || chunk.id
                        .equals(ChunkHelper.tIME)))
                    return true;
                if (maskMatch(copyFromMask, ChunkCopyBehaviour.COPY_UNKNOWN)
                        && ChunkHelper.isUnknown(chunk))
                    return true;
            }
            return false;
        }

    };
}
 
开发者ID:4142,项目名称:audio2png,代码行数:48,代码来源:ChunkCopyBehaviour.java

示例14: timePNGJEncode

import ar.com.hjg.pngj.ImageInfo; //导入依赖的package包/类
@Test
public void timePNGJEncode() throws Exception {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ColorModel colorModel = image.getColorModel();
    boolean indexed = colorModel instanceof IndexColorModel;
    boolean hasAlpha = colorModel.hasAlpha();
    boolean grayscale = !indexed && colorModel.getNumColorComponents() == 1;
    ImageInfo ii = new ImageInfo(image.getWidth(), image.getHeight(), 8, hasAlpha, grayscale,
            indexed);
    PngWriter pw = new PngWriter(bos, ii);
    pw.setCompLevel(4);
    // pw.setDeflaterStrategy(Deflater.NO_COMPRESSION);
    pw.setFilterType(ar.com.hjg.pngj.FilterType.getByVal(filterType.getType()));

    if (indexed) {
        IndexColorModel icm = (IndexColorModel) colorModel;
        PngChunkPLTE palette = pw.getMetadata().createPLTEChunk();
        int ncolors = icm.getNumComponents();
        palette.setNentries(ncolors);
        for (int i = 0; i < ncolors; i++) {
            palette.setEntry(i, icm.getRed(i), icm.getGreen(i), icm.getBlue(i));
        }
        if (icm.hasAlpha()) {
            PngChunkTRNS transparent = new PngChunkTRNS(ii);
            int[] alpha = new int[ncolors];
            for (int i = 0; i < ncolors; i++) {
                alpha[i] = icm.getAlpha(i);
            }
            transparent.setPalletteAlpha(alpha);
            pw.getChunksList().queue(transparent);

        }
    }

    ScanlineProvider scanlines = ScanlineProviderFactory.getProvider(image);
    for (int row = 0; row < image.getHeight(); row++) {
        pw.writeRow(scanlines);

    }
    pw.end();
    byte[] png = bos.toByteArray();
    collectPng("pngj", png);
}
 
开发者ID:aaime,项目名称:png-experiments,代码行数:44,代码来源:BufferedImageEncodingBenchmark.java

示例15: timePNGJEncode

import ar.com.hjg.pngj.ImageInfo; //导入依赖的package包/类
public void timePNGJEncode(ar.com.hjg.pngj.FilterType filterType, String name) throws Exception {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ColorModel colorModel = image.getColorModel();
    boolean indexed = colorModel instanceof IndexColorModel;
    boolean hasAlpha = colorModel.hasAlpha();
    boolean grayscale = !indexed && colorModel.getNumColorComponents() == 1;
    ImageInfo ii = new ImageInfo(image.getWidth(), image.getHeight(), 8, hasAlpha, grayscale,
            indexed);
    PngWriter pw = new PngWriter(bos, ii);
    pw.setCompLevel(compression);
    pw.setFilterType(filterType);

    if (indexed) {
        IndexColorModel icm = (IndexColorModel) colorModel;
        PngChunkPLTE palette = pw.getMetadata().createPLTEChunk();
        int ncolors = icm.getNumComponents();
        palette.setNentries(ncolors);
        for (int i = 0; i < ncolors; i++) {
            palette.setEntry(i, icm.getRed(i), icm.getGreen(i), icm.getBlue(i));
        }
        if (icm.hasAlpha()) {
            PngChunkTRNS transparent = new PngChunkTRNS(ii);
            int[] alpha = new int[ncolors];
            for (int i = 0; i < ncolors; i++) {
                alpha[i] = icm.getAlpha(i);
            }
            transparent.setPalletteAlpha(alpha);
            pw.getChunksList().queue(transparent);

        }
    }

    ScanlineProvider scanlines = ScanlineProviderFactory.getProvider(image);
    for (int row = 0; row < image.getHeight(); row++) {
        pw.writeRow(scanlines);
    }
    pw.end();
    byte[] png = bos.toByteArray();
    collectPng(name, png);
}
 
开发者ID:aaime,项目名称:png-experiments,代码行数:41,代码来源:SamplesEncodingBenchmark.java


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