Example usage for java.awt.image Raster getDataElements

List of usage examples for java.awt.image Raster getDataElements

Introduction

In this page you can find the example usage for java.awt.image Raster getDataElements.

Prototype

public Object getDataElements(int x, int y, Object outData) 

Source Link

Document

Returns data for a single pixel in a primitive array of type TransferType.

Usage

From source file:CheckAlignmentOpImage.java

public Raster computeTile(int x, int y) {
    Raster r1 = source1.getTile(x, y);
    Raster r2 = source2.getTile(x, y);

    int xBounds = r1.getWidth();
    if (r2.getWidth() < xBounds)
        xBounds = r2.getWidth();//  w ww .j a v a  2 s . c  om
    int yBounds = r1.getHeight();
    if (r2.getHeight() < yBounds)
        yBounds = r2.getHeight();

    WritableRaster wr;
    wr = r1.createCompatibleWritableRaster(xBounds, yBounds);

    int tmpi;
    int tmpj;
    for (int i = 0; i < wr.getWidth(); i++)
        for (int j = 0; j < wr.getHeight(); j++) {
            tmpi = i / samplingPeriod;
            tmpj = j / samplingPeriod;
            if ((tmpi % 2 == 0) && (tmpj % 2 == 0))
                wr.setDataElements(i, j, r2.getDataElements(i, j, null));
            else if ((tmpi % 2 != 0) && (tmpj % 2 != 0))
                wr.setDataElements(i, j, r2.getDataElements(i, j, null));
            else
                wr.setDataElements(i, j, r1.getDataElements(i, j, null));
        }
    return wr;
}

From source file:org.apache.xmlgraphics.ps.PSImageUtils.java

/**
 * Extracts a packed RGB integer array of a RenderedImage.
 * @param img the image/*from www.  j  a v a  2 s  .co  m*/
 * @param startX the starting X coordinate
 * @param startY the starting Y coordinate
 * @param w the width of the cropped image
 * @param h the height of the cropped image
 * @param rgbArray the prepared integer array to write to
 * @param offset offset in the target array
 * @param scansize width of a row in the target array
 * @return the populated integer array previously passed in as rgbArray parameter
 */
public static int[] getRGB(RenderedImage img, int startX, int startY, int w, int h, int[] rgbArray, int offset,
        int scansize) {
    Raster raster = img.getData();
    int yoff = offset;
    int off;
    Object data;
    int nbands = raster.getNumBands();
    int dataType = raster.getDataBuffer().getDataType();
    switch (dataType) {
    case DataBuffer.TYPE_BYTE:
        data = new byte[nbands];
        break;
    case DataBuffer.TYPE_USHORT:
        data = new short[nbands];
        break;
    case DataBuffer.TYPE_INT:
        data = new int[nbands];
        break;
    case DataBuffer.TYPE_FLOAT:
        data = new float[nbands];
        break;
    case DataBuffer.TYPE_DOUBLE:
        data = new double[nbands];
        break;
    default:
        throw new IllegalArgumentException("Unknown data buffer type: " + dataType);
    }

    if (rgbArray == null) {
        rgbArray = new int[offset + h * scansize];
    }

    ColorModel colorModel = img.getColorModel();
    for (int y = startY; y < startY + h; y++, yoff += scansize) {
        off = yoff;
        for (int x = startX; x < startX + w; x++) {
            rgbArray[off++] = colorModel.getRGB(raster.getDataElements(x, y, data));
        }
    }

    return rgbArray;
}

From source file:org.pentaho.di.core.gui.SwingGC.java

private void drawImage(SwingUniversalImage image, int locationX, int locationY, int imageSize) {
    if (isDrawingPixelatedImages() && image.isBitmap()) {
        BufferedImage img = image.getAsBitmapForSize(imageSize, imageSize);
        ColorModel cm = img.getColorModel();
        Raster raster = img.getRaster();

        for (int x = 0; x < img.getWidth(observer); x++) {
            for (int y = 0; y < img.getHeight(observer); y++) {
                Object pix = raster.getDataElements(x, y, null);
                gc.setColor(new Color(cm.getRed(pix), cm.getGreen(pix), cm.getBlue(pix), cm.getAlpha(pix)));
                gc.setStroke(new BasicStroke(1.0f));
                gc.drawLine(locationX + xOffset + x, locationY + yOffset + y, locationX + xOffset + x + 1,
                        locationY + yOffset + y + 1);
            }/*from   w  ww. j  a v  a  2s . co m*/
        }
    } else {
        image.drawToGraphics(gc, locationX, locationY, imageSize, imageSize);
    }
}

From source file:org.pentaho.di.core.gui.SwingGC.java

private void drawImage(SwingUniversalImage image, int centerX, int centerY, double angle, int imageSize) {
    if (isDrawingPixelatedImages() && image.isBitmap()) {
        BufferedImage img = image.getAsBitmapForSize(imageSize, imageSize, angle);
        ColorModel cm = img.getColorModel();
        Raster raster = img.getRaster();

        int offx = centerX + xOffset - img.getWidth() / 2;
        int offy = centerY + yOffset - img.getHeight() / 2;
        for (int x = 0; x < img.getWidth(observer); x++) {
            for (int y = 0; y < img.getHeight(observer); y++) {
                Object pix = raster.getDataElements(x, y, null);
                gc.setColor(new Color(cm.getRed(pix), cm.getGreen(pix), cm.getBlue(pix), cm.getAlpha(pix)));
                gc.setStroke(new BasicStroke(1.0f));
                gc.drawLine(offx + x, offy + y, offx + x + 1, offy + y + 1);
            }//from www.  j  ava 2 s . c om
        }
    } else {
        image.drawToGraphics(gc, centerX, centerY, imageSize, imageSize, angle);
    }
}