Example usage for java.awt.image BufferedImage getData

List of usage examples for java.awt.image BufferedImage getData

Introduction

In this page you can find the example usage for java.awt.image BufferedImage getData.

Prototype

public Raster getData() 

Source Link

Document

Returns the image as one large tile.

Usage

From source file:com.celements.photo.image.GenerateThumbnail.java

private String getHashOfImage(BufferedImage img) throws NoSuchAlgorithmException {
    MessageDigest digest = MessageDigest.getInstance(ImageLibStrings.HASHING_ALGORITHM);

    PixelAccessor pa = new PixelAccessor(img);
    UnpackedImageData uid = pa.getPixels(img.getData(), img.getData().getBounds(), DataBuffer.TYPE_BYTE, false);
    byte[][] pixels = uid.getByteData();
    for (int i = 0; i < pixels.length; i++) {
        digest.update(pixels[i]);//from  w  ww .  j  av  a  2 s  .c  om
    }

    return new String(digest.digest());
}

From source file:org.csa.rstb.dat.toolviews.HaAlphaPlotPanel.java

private byte[] getValidData(BufferedImage image) {
    if (image != null && image.getColorModel() instanceof IndexColorModel
            && image.getData().getDataBuffer() instanceof DataBufferByte) {
        return ((DataBufferByte) image.getData().getDataBuffer()).getData();
    }/* w ww.j  a v a2  s.  c  o  m*/
    return null;
}

From source file:it.tidalwave.imageio.test.ImageReaderTestSupport.java

/*******************************************************************************************************************
 *
 *
 ******************************************************************************************************************/
@Nonnull//ww  w . j  a  va 2s  . c o  m
@Deprecated
protected BufferedImage assertLoadImage(final @Nonnull ImageReader ir,
        final @CheckForNull RAWImageReadParam readParam, final @Nonnegative int width,
        final @Nonnegative int height, final @Nonnegative int bandCount, final @Nonnegative int sampleSize)
        throws IOException {
    final BufferedImage image = ir.read(0, readParam);
    assertNotNull(image);
    final Dimension imageSize = new Dimension(image.getWidth(), image.getHeight());
    final Dimension expectedSize = new Dimension(width, height);
    assertEquals("loaded image size: ", expectedSize, imageSize);
    assertEquals("loaded image band count", bandCount, image.getData().getNumBands());

    for (int i = 0; i < bandCount; i++) {
        assertEquals("loaded image sample size for band " + i, sampleSize,
                image.getData().getSampleModel().getSampleSize(i));
    }

    return image;
}

From source file:it.tidalwave.imageio.test.ImageReaderTestSupport.java

/*******************************************************************************************************************
 * //w  ww  .  ja v  a  2s. co  m
 * 
 ******************************************************************************************************************/
@Nonnull
protected BufferedImage assertLoadImage(final @Nonnull ImageReader ir,
        final @CheckForNull RAWImageReadParam readParam, final @Nonnegative int width,
        final @Nonnegative int height, final @Nonnegative int bandCount, final @Nonnegative int sampleSize,
        final int type) throws IOException {
    final BufferedImage image = ir.read(0, readParam);
    assertNotNull(image);
    final Dimension imageSize = new Dimension(image.getWidth(), image.getHeight());
    final Dimension expectedSize = new Dimension(width, height);
    assertEquals("loaded image size: ", expectedSize, imageSize);
    assertEquals("loaded image band count", bandCount, image.getData().getNumBands());
    assertEquals(type, image.getType());

    for (int i = 0; i < bandCount; i++) {
        assertEquals("loaded image sample size for band " + i, sampleSize,
                image.getData().getSampleModel().getSampleSize(i));
    }

    return image;
}

From source file:TextureByReference.java

public static BufferedImage convertToCustomRGB(BufferedImage bImage) {
    if (bImage.getType() != BufferedImage.TYPE_INT_ARGB) {
        ImageOps.convertImage(bImage, BufferedImage.TYPE_INT_ARGB);
    }/*from  w ww . jav a2s  . com*/

    int width = bImage.getWidth();
    int height = bImage.getHeight();

    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    int[] nBits = { 8, 8, 8 };
    ColorModel cm = new ComponentColorModel(cs, nBits, false, false, Transparency.OPAQUE, 0);
    int[] bandOffset = { 0, 1, 2 };

    WritableRaster newRaster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height, width * 3, 3,
            bandOffset, null);
    byte[] byteData = ((DataBufferByte) newRaster.getDataBuffer()).getData();
    Raster origRaster = bImage.getData();
    int[] pixel = new int[4];
    int k = 0;
    for (int j = 0; j < height; j++) {
        for (int i = 0; i < width; i++) {
            pixel = origRaster.getPixel(i, j, pixel);
            byteData[k++] = (byte) (pixel[0]);
            byteData[k++] = (byte) (pixel[1]);
            byteData[k++] = (byte) (pixel[2]);
        }
    }
    BufferedImage newImage = new BufferedImage(cm, newRaster, false, null);
    //  if (newImage.getType() == BufferedImage.TYPE_CUSTOM) {
    //    System.out.println("Type is custom");
    //  }
    return newImage;
}

From source file:TextureByReference.java

public static BufferedImage convertToCustomRGBA(BufferedImage bImage) {
    if (bImage.getType() != BufferedImage.TYPE_INT_ARGB) {
        ImageOps.convertImage(bImage, BufferedImage.TYPE_INT_ARGB);
    }/*from   w w w  .  j ava  2s  . c  o  m*/

    int width = bImage.getWidth();
    int height = bImage.getHeight();

    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    int[] nBits = { 8, 8, 8, 8 };
    ColorModel cm = new ComponentColorModel(cs, nBits, true, false, Transparency.OPAQUE, 0);
    int[] bandOffset = { 0, 1, 2, 3 };

    WritableRaster newRaster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height, width * 4, 4,
            bandOffset, null);
    byte[] byteData = ((DataBufferByte) newRaster.getDataBuffer()).getData();
    Raster origRaster = bImage.getData();
    int[] pixel = new int[4];
    int k = 0;
    for (int j = 0; j < height; j++) {
        for (int i = 0; i < width; i++) {
            pixel = origRaster.getPixel(i, j, pixel);
            byteData[k++] = (byte) (pixel[0]);
            byteData[k++] = (byte) (pixel[1]);
            byteData[k++] = (byte) (pixel[2]);
            byteData[k++] = (byte) (pixel[3]);
        }
    }
    BufferedImage newImage = new BufferedImage(cm, newRaster, false, null);
    //  if (newImage.getType() == BufferedImage.TYPE_CUSTOM) {
    //    System.out.println("Type is custom");
    //  }
    return newImage;
}

From source file:it.tidalwave.imageio.test.ImageReaderTestSupport.java

/*******************************************************************************************************************
 * //from  ww  w  .  j  av  a2  s  .  co  m
 * 
 ******************************************************************************************************************/
protected void assertRaster(final @Nonnull BufferedImage image, final @Nonnull String path,
        final @Nonnull String expectedRasterMD5, final @Nonnull String suffix)
        throws IOException, NoSuchAlgorithmException {
    final File targetDirectory = new File("target/converted-images/");
    final File tiffFile = new File(targetDirectory, path.replace("https://", "").replace("http://", "") + suffix
            + "-" + System.getProperty("java.version") + ".tiff");

    if (Boolean.getBoolean("jrawio.dumpImageAsTIFF")) {
        tiffFile.getParentFile().mkdirs();
        logger.info("***************** Writing %s...", tiffFile.getAbsolutePath());
        System.err.printf(">>>> Writing %s...\n", tiffFile.getAbsolutePath());
        ImageIO.write(image, "TIFF", tiffFile);
    }

    final Raster raster = image.getData();

    if (Boolean.getBoolean("jrawio.dumpRasterAsText")) {
        final File textDumpFile = new File(
                tiffFile.getAbsolutePath() + "-" + System.getProperty("java.version") + ".txt");
        dumpRasterAsText(raster, textDumpFile);
    }

    if (expectedRasterMD5 != null) // we temporarily accept null since there's no value for thumbnails
    {
        final MessageDigest md5 = md5(raster);

        // Comparisons are broken with JDK 1.5.0, don't make tests fail under Hudson.
        // See http://jrawio.tidalwave.it/issues/browse/JRW-162
        //        if (System.getProperty("java.version").contains("1.5.0"))
        //          {
        //            logger.warning("Not testing raster's MD5 on Java 5 because of JRW-162");
        //          }
        //        else
        //          {
        assertEquals(expectedRasterMD5, asString(md5.digest()));
        //          }
    }
}

From source file:com.sat.dbds.vcs.login.LoginStepDef.java

/**
 * This method will try to match images and conclude if
 * the are identical.//from   w  ww. jav a 2 s  . c o  m
 *
 * @param sourceImage the source image
 * @param targetImage the target image
 * @return true, if successful
 * @throws IOException Signals that an I/O exception has occurred.
 */
boolean doImagesMatch(String sourceImage, String targetImage) throws IOException {

    LogHandler.info("Source image is:" + sourceImage);
    LogHandler.info("Target image is:" + targetImage);

    File fileInput = new File(sourceImage);
    File fileOutPut = new File(targetImage);

    BufferedImage bufFileInput = ImageIO.read(fileInput);
    DataBuffer dataFileInput = bufFileInput.getData().getDataBuffer();
    int sizeFileInput = dataFileInput.getSize();

    BufferedImage bufFileOutPut = ImageIO.read(fileOutPut);
    DataBuffer dataFileOutPut = bufFileOutPut.getData().getDataBuffer();
    int sizeFileOutPut = dataFileOutPut.getSize();

    boolean matchFlag = true;
    if (sizeFileInput == sizeFileOutPut) {
        for (int j = 0; j < sizeFileInput; j++) {
            if (dataFileInput.getElem(j) != dataFileOutPut.getElem(j)) {
                matchFlag = false;
                break;
            }
        }
    } else
        matchFlag = false;

    return matchFlag;
}

From source file:lucee.runtime.img.Image.java

private static BufferedImage addAlpha(BufferedImage src, BufferedImage alpha, int x, int y) {
    int w = src.getWidth();
    int h = src.getHeight();
    BufferedImage bi = new BufferedImage(w, h, 2);
    WritableRaster wr = bi.getWritableTile(0, 0);
    WritableRaster wr3 = wr.createWritableChild(0, 0, w, h, 0, 0, new int[] { 0, 1, 2 });
    WritableRaster wr1 = wr.createWritableChild(0, 0, w, h, 0, 0, new int[] { 3 });
    wr3.setRect(src.getData());
    wr1.setRect(alpha.getData());//from w w w.  ja v a 2  s  . c  om
    bi.releaseWritableTile(0, 0);
    return bi;
}

From source file:contact.Contact.java

private Boolean comparePictures(String strPathToComparePicture) {
    BufferedImage imageA;
    BufferedImage imageB;/*from  w w  w  . j a v  a 2  s. c  o m*/

    File fileImageA = new File(this.strPathToContactPicture);
    File fileImageB = new File(strPathToComparePicture);

    if (!fileImageA.exists() || !fileImageB.exists()) {
        return false;
    }

    try {
        imageA = ImageIO.read(new File(this.strPathToContactPicture));
        imageB = ImageIO.read(new File(strPathToComparePicture));

    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }

    int[] pixelOfA = new int[imageA.getWidth() * imageA.getHeight()];
    imageA.getData().getPixel(0, 0, pixelOfA);

    int[] pixelOfB = new int[imageB.getWidth() * imageB.getHeight()];
    imageB.getData().getPixel(0, 0, pixelOfB);

    return Arrays.equals(pixelOfA, pixelOfB);
}