Example usage for java.awt.image BufferedImage getWidth

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

Introduction

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

Prototype

public int getWidth() 

Source Link

Document

Returns the width of the BufferedImage .

Usage

From source file:no.dusken.aranea.service.StoreImageServiceImpl.java

public Image changeImage(File file, Image image) throws IOException {

    String hash = MD5.asHex(MD5.getHash(file));

    if (isBlank(hash)) {
        throw new IOException("Could not get hash from " + file.getAbsolutePath());
    }/*from   w w w .  ja  v a2 s. c om*/

    Image existingImage = imageService.getImageByHash(hash);
    if (existingImage != null) {
        log.info("Imported existing Image: {} from the user", existingImage.toString());
        file.delete();
        return existingImage;
    } else {
        image.setHash(hash);

        BufferedImage rendImage = ImageIO.read(file);
        image.setHeight(rendImage.getHeight());
        image.setWidth(rendImage.getWidth());
        image.setFileSize(file.length());
        FileUtils.copyFile(file, new File(imageDirectory + "/" + image.getUrl()));

        file.delete();
        log.debug("Imported Image: {} from {}", image.toString(), file.getAbsolutePath());

        return imageService.saveOrUpdate(image);
    }
}

From source file:org.jtheque.movies.services.impl.FFMpegServiceTest.java

@Test
public void generatePreviewImage() {
    BufferedImage image = ffmMpegService.generatePreviewImage(new File(testFolder + "gok.avi"), "5");

    assertNotNull(image);//from  www. j  a v  a  2  s.  c  o m

    assertEquals(200, image.getWidth());
}

From source file:org.jtheque.movies.services.impl.FFMpegServiceTest.java

@Test
public void generateRandomPreviewImage() {
    BufferedImage image = ffmMpegService.generateRandomPreviewImage(new File(testFolder + "gok.avi"));

    assertNotNull(image);/*from  w w  w  .  j av  a  2 s . com*/

    assertEquals(200, image.getWidth());
}

From source file:org.jtheque.movies.services.impl.FFMpegServiceTest.java

@Test
public void testGenerateImageFromUserInput() {
    BufferedImage image = ffmMpegService.generateImageFromUserInput(new File(testFolder + "test.jpg"));

    assertNotNull(image);//w w  w.  j  a va  2s.com

    assertEquals(200, image.getWidth());
}

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 w  w . ja  v  a 2s. c om

    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 ww  w.j ava2  s  .com*/

    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:net.rptools.lib.image.ThumbnailManager.java

private BufferedImage getCachedThumbnail(File file) {
    File thumbnailFile = getThumbnailFile(file);

    if (!thumbnailFile.exists()) {
        return null;
    }/* w  w  w .j  av a2 s.c  om*/
    try {
        // Check that it hasn't changed on disk
        if (file.lastModified() > thumbnailFile.lastModified()) {
            return null;
        }
        // Get the thumbnail
        BufferedImage thumbnail = ImageIO.read(thumbnailFile);

        // Check that we have the size we want
        if (thumbnail.getWidth() != thumbnailSize.width && thumbnail.getHeight() != thumbnailSize.height) {
            return null;
        }
        return thumbnail;
    } catch (IOException ioe) {
        return null;
    }
}

From source file:com.dianping.imcaptcha.strategy.WaveFilter.java

public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    int width = src.getWidth();
    int height = src.getHeight();
    int type = src.getType();
    WritableRaster srcRaster = src.getRaster();

    originalSpace = new Rectangle(0, 0, width, height);
    transformedSpace = new Rectangle(0, 0, width, height);
    transformSpace(transformedSpace);/*  w  ww  . j  av a 2  s .  c  o  m*/

    if (dst == null) {
        ColorModel dstCM = src.getColorModel();
        dst = new BufferedImage(dstCM,
                dstCM.createCompatibleWritableRaster(transformedSpace.width, transformedSpace.height),
                dstCM.isAlphaPremultiplied(), null);
    }
    WritableRaster dstRaster = dst.getRaster();

    int[] inPixels = getRGB(src, 0, 0, width, height, null);

    if (interpolation == NEAREST_NEIGHBOUR)
        return filterPixelsNN(dst, width, height, inPixels, transformedSpace);

    int srcWidth = width;
    int srcHeight = height;
    int srcWidth1 = width - 1;
    int srcHeight1 = height - 1;
    int outWidth = transformedSpace.width;
    int outHeight = transformedSpace.height;
    int outX, outY;
    int index = 0;
    int[] outPixels = new int[outWidth];
    float radius = srcHeight * 1.0f / 2 / (float) Math.PI;
    outX = transformedSpace.x;
    outY = transformedSpace.y;
    float[] out = new float[2];

    for (int y = 0; y < outHeight; y++) {
        for (int x = 0; x < outWidth; x++) {
            transformInverse(outX + x, outY + y, out, radius);
            int srcX = (int) Math.floor(out[0]);
            int srcY = (int) Math.floor(out[1]);
            float xWeight = out[0] - srcX;
            float yWeight = out[1] - srcY;
            int nw, ne, sw, se;

            if (srcX >= 0 && srcX < srcWidth1 && srcY >= 0 && srcY < srcHeight1) {
                // Easy case, all corners are in the image
                int i = srcWidth * srcY + srcX;
                nw = inPixels[i];
                ne = inPixels[i + 1];
                sw = inPixels[i + srcWidth];
                se = inPixels[i + srcWidth + 1];
            } else {
                // Some of the corners are off the image
                nw = getPixel(inPixels, srcX, srcY, srcWidth, srcHeight);
                ne = getPixel(inPixels, srcX + 1, srcY, srcWidth, srcHeight);
                sw = getPixel(inPixels, srcX, srcY + 1, srcWidth, srcHeight);
                se = getPixel(inPixels, srcX + 1, srcY + 1, srcWidth, srcHeight);
            }
            outPixels[x] = ImageMath.bilinearInterpolate(xWeight, yWeight, nw, ne, sw, se);
        }
        setRGB(dst, 0, y, transformedSpace.width, 1, outPixels);
    }
    return dst;
}

From source file:com.t3.image.ThumbnailManager.java

private BufferedImage getCachedThumbnail(File file) {

    File thumbnailFile = getThumbnailFile(file);

    if (!thumbnailFile.exists()) {
        return null;
    }//  w w  w  . j  av  a  2  s.  c  o  m

    try {
        // Check that it hasn't changed on disk
        if (file.lastModified() > thumbnailFile.lastModified()) {
            return null;
        }

        // Get the thumbnail
        BufferedImage thumbnail = ImageIO.read(thumbnailFile);

        // Check that we have the size we want
        if (thumbnail.getWidth() != thumbnailSize.width && thumbnail.getHeight() != thumbnailSize.height) {
            return null;
        }

        return thumbnail;
    } catch (IOException ioe) {
        return null;
    }
}

From source file:com.softenido.cafedark.image.hash.ImageHashBuilder.java

public Hash buildHash(BufferedImage image) {
    count.incrementAndGet();// ww  w .j a va2  s.com
    image = scale.filter(image);

    int w = image.getWidth();
    int h = image.getHeight();

    //        JFrame frame = new JFrame();
    //        frame.setTitle("["+w+"x"+h+"]"+" ");
    //        frame.add(new JLabel(new ImageIcon(image)));
    //        frame.setVisible(true);
    //        frame.pack();

    int[] pixels = null;
    pixels = image.getRGB(0, 0, w, h, pixels, 0, w);
    if (colorThreshold > 0 && gray) {
        byte[] hash = new byte[pixels.length];
        for (int i = 0; i < hash.length; i++) {
            hash[i] = (byte) (pixels[i] & 0xff);
        }
        int hc = (w * h) + (w - h);
        //            System.out.println(Arrays.toString(hash));
        return new StickyImageHash(w, h, hc, hash, colorThreshold, countThresold);
    }
    if (colorThreshold > 0) {
        byte[] hash = ArrayUtils.getByteArray(pixels);
        int hc = (w * h) + (w - h);
        System.out.println(Arrays.toString(hash));
        return new StickyImageHash(w, h, hc, hash, colorThreshold, countThresold);
    }
    byte[] hash = buildDigest(pixels);
    int hc = (w * h) + (w - h) + Arrays.hashCode(hash);
    System.out.println(Arrays.toString(hash));
    return new ImageHash(w, h, hc, hash);
}