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


Java ImageLineInt.getScanline方法代码示例

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


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

示例1: getPixelValues

import ar.com.hjg.pngj.ImageLineInt; //导入方法依赖的package包/类
/**
 * Get the pixel values of the image as 16 bit unsigned integer values
 *
 * @param imageBytes image bytes
 * @return 16 bit unsigned integer pixel values
 */
public int[] getPixelValues(byte[] imageBytes) {

    PngReaderInt reader = new PngReaderInt(new ByteArrayInputStream(imageBytes));
    validateImageType(reader);
    int[] pixels = new int[reader.imgInfo.cols * reader.imgInfo.rows];
    int rowNumber = 0;
    while (reader.hasMoreRows()) {
        ImageLineInt row = reader.readRowInt();
        int[] rowValues = row.getScanline();
        System.arraycopy(rowValues, 0, pixels, rowNumber * reader.imgInfo.cols, rowValues.length);
        rowNumber++;
    }
    reader.close();

    return pixels;
}
 
开发者ID:ngageoint,项目名称:geopackage-android,代码行数:23,代码来源:ElevationTilesPng.java

示例2: drawTile

import ar.com.hjg.pngj.ImageLineInt; //导入方法依赖的package包/类
/**
 * Draw an elevation image tile from the flat array of "unsigned short"
 * pixel values of length tileWidth * tileHeight where each pixel is at: (y
 * * tileWidth) + x
 *
 * @param pixelValues "unsigned short" pixel values of length tileWidth * tileHeight
 * @param tileWidth   tile width
 * @param tileHeight  tile height
 * @return elevation image tile
 */
public ElevationPngImage drawTile(short[] pixelValues, int tileWidth,
                                  int tileHeight) {

    ElevationPngImage image = createImage(tileWidth, tileHeight);
    PngWriter writer = image.getWriter();
    for (int y = 0; y < tileHeight; y++) {
        ImageLineInt row = new ImageLineInt(writer.imgInfo, new int[tileWidth]);
        int[] rowLine = row.getScanline();
        for (int x = 0; x < tileWidth; x++) {
            short pixelValue = pixelValues[(y * tileWidth) + x];
            setPixelValue(rowLine, x, pixelValue);
        }
        writer.writeRow(row);
    }
    writer.end();
    image.flushStream();

    return image;
}
 
开发者ID:ngageoint,项目名称:geopackage-android,代码行数:30,代码来源:ElevationTilesPng.java

示例3: copyScales

import ar.com.hjg.pngj.ImageLineInt; //导入方法依赖的package包/类
public static void copyScales(ImageLineInt[] lines) {
    for (int index = 0; index < writers.length; index++) {
        int scale = (int) Math.pow(2, index + 1);
        PngWriter writer = writers[index];
        ImageLineInt outLine = new ImageLineInt(writer.imgInfo);
        int[] outScan = outLine.getScanline();
        for (int i = 0; i < lines.length; i += scale) {
            ImageLineInt inLine = lines[i];
            int[] inScan = inLine.getScanline();
            for (int outIndex = 0; outIndex < outScan.length - 3; outIndex += 3) {
                int inIndex = outIndex * scale;
                if (inIndex + 3 >= inScan.length) {
                    break; //cut short in case size does not line up exactly.
                }
                System.arraycopy(inScan, inIndex, outScan, outIndex, 3);
            }
            writer.writeRow(outLine);
        }
    }
}
 
开发者ID:warriordog,项目名称:MapMaster,代码行数:21,代码来源:MapScaler.java

示例4: getPixelValue

import ar.com.hjg.pngj.ImageLineInt; //导入方法依赖的package包/类
/**
 * Get the pixel value as a 16 bit unsigned integer value
 *
 * @param imageBytes image bytes
 * @param x          x coordinate
 * @param y          y coordinate
 * @return pixel value
 */
public int getPixelValue(byte[] imageBytes, int x, int y) {

    PngReaderInt reader = new PngReaderInt(new ByteArrayInputStream(imageBytes));
    validateImageType(reader);
    ImageLineInt row = (ImageLineInt) reader.readRow(y);
    int pixelValue = row.getScanline()[x];
    reader.close();

    return pixelValue;
}
 
开发者ID:ngageoint,项目名称:geopackage-android,代码行数:19,代码来源:ElevationTilesPng.java

示例5: encodeIndexedPNG

import ar.com.hjg.pngj.ImageLineInt; //导入方法依赖的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

示例6: encodeIndexedPNG

import ar.com.hjg.pngj.ImageLineInt; //导入方法依赖的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

示例7: write

import ar.com.hjg.pngj.ImageLineInt; //导入方法依赖的package包/类
@Override
public void write(Image image, OutputStream out) throws IOException {

    if (image.awt().getType() == BufferedImage.TYPE_INT_ARGB) {

        ImageInfo imi = new ImageInfo(image.width, image.height, 8, true);

        ar.com.hjg.pngj.PngWriter writer = new ar.com.hjg.pngj.PngWriter(out, imi);
        writer.setCompLevel(compressionLevel);
        writer.setFilterType(FilterType.FILTER_DEFAULT);

        DataBufferInt db = (DataBufferInt) image.awt().getRaster().getDataBuffer();
        if (db.getNumBanks() != 1) throw new RuntimeException("This method expects one bank");

        SinglePixelPackedSampleModel samplemodel = (SinglePixelPackedSampleModel) image.awt().getSampleModel();
        ImageLineInt line = new ImageLineInt(imi);
        int[] dbbuf = db.getData();

        for (int row = 0; row < imi.rows; row++) {
            int elem = samplemodel.getOffset(0, row);
            int j = 0;
            for (int col = 0; col < imi.cols; col++) {
                int sample = dbbuf[elem];
                elem = elem + 1;
                line.getScanline()[j] = (sample & 0xFF0000) >> 16; // R
                j = j + 1;
                line.getScanline()[j] = (sample & 0xFF00) >> 8; // G
                j = j + 1;
                line.getScanline()[j] = sample & 0xFF; // B
                j = j + 1;
                line.getScanline()[j] = ((sample & 0xFF000000) >> 24) & 0xFF; // A
                j = j + 1;
            }
            writer.writeRow(line, row);
        }
        writer.end();// end calls close

    } else {
        ImageIO.write(image.awt(), "png", out);
    }
}
 
开发者ID:sksamuel,项目名称:scrimage,代码行数:42,代码来源:PngWriter.java


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