Example usage for java.awt.image BufferedImage getHeight

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

Introduction

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

Prototype

public int getHeight() 

Source Link

Document

Returns the height of the BufferedImage .

Usage

From source file:imageprocessingproject.ImageHistogram.java

public static BufferedImage autoContrastImage(BufferedImage image) {
    createContrastLUT(image);/*from  w w  w  . ja  v  a2  s  . com*/

    int height = image.getHeight();
    int width = image.getWidth();
    int r, g, b;
    Color c;

    BufferedImage tempImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            c = new Color(image.getRGB(i, j));
            r = (int) (255 * contrast_lut[c.getRed()]);
            g = (int) (255 * contrast_lut[c.getGreen()]);
            b = (int) (255 * contrast_lut[c.getBlue()]);
            tempImage.setRGB(i, j, new Color(r, g, b, c.getAlpha()).getRGB());
        }
    }

    return tempImage;
}

From source file:filtros.histograma.Histograma.java

public static void GetData(BufferedImage image) {
    //Obtem a largura e a altura da imagem original
    int width = image.getWidth();
    int height = image.getHeight();

    //Inicializa o array
    data = new int[256];

    //Aplica o filtro de escala de cinza na imagem
    BufferedImage temp = GrayScale.Apply(image);

    //Loop que percorre todos os pixels da imagem
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            //Obtem o valor RGB do pixel
            int pixel = temp.getRGB(i, j);
            int r = (int) ((pixel & 0x00FF0000) >>> 16); //Recupera o valor de Red
            int g = (int) ((pixel & 0x0000FF00) >>> 8); //Recupera o valor de Green
            int b = (int) (pixel & 0x000000FF); //Recupera o valor de Blue

            //Incrementa o valor do array na posio referente ao tom RGB
            data[r] += 1;/*from w  ww  . j a  v a 2  s. co m*/
            data[g] += 1;
            data[b] += 1;
        }
    }
}

From source file:UploadImage.java

public static BufferedImage shrink(BufferedImage image, int n) {

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

    BufferedImage shrunkImage = new BufferedImage(w, h, image.getType());

    for (int y = 0; y < h; ++y)
        for (int x = 0; x < w; ++x)
            shrunkImage.setRGB(x, y, image.getRGB(x * n, y * n));

    return shrunkImage;
}

From source file:com.datazuul.iiif.presentation.api.ManifestGenerator.java

private static void addPage(String urlPrefix, String imageDirectoryName, List<Canvas> canvases, int pageCounter,
        Path file) throws IOException, URISyntaxException {
    Path fileName = file.getFileName();
    System.out.println(fileName.toAbsolutePath());

    BufferedImage bimg = ImageIO.read(file.toFile());
    int width = bimg.getWidth();
    int height = bimg.getHeight();

    // add a new page
    Canvas canvas1 = new Canvas(urlPrefix + imageDirectoryName + "/canvas/canvas-" + pageCounter,
            "p-" + pageCounter, height, width);
    canvases.add(canvas1);/*  w  ww  .  java 2s  .com*/

    List<Image> images = new ArrayList<>();
    canvas1.setImages(images);

    Image image1 = new Image();
    image1.setOn(canvas1.getId());
    images.add(image1);

    ImageResource imageResource1 = new ImageResource(
            urlPrefix + imageDirectoryName + "/" + fileName.toString());
    imageResource1.setHeight(height);
    imageResource1.setWidth(width);
    image1.setResource(imageResource1);

    Service service1 = new Service(urlPrefix + imageDirectoryName + "/" + fileName.toString() + "?");
    service1.setContext("http://iiif.io/api/image/2/context.json");
    service1.setProfile("http://iiif.io/api/image/2/level1.json");
    imageResource1.setService(service1);
}

From source file:Main.java

/**
 * Pads the given {@link BufferedImage} on all sides by the given padding amount.
 *
 * @param source  The source image.//from w  ww. j  a va  2s  .  c  om
 * @param padding The amount to pad on all sides, in pixels.
 * @return A new, padded image, or the source image if no padding is performed.
 */
public static BufferedImage paddedImage(BufferedImage source, int padding) {
    if (padding == 0) {
        return source;
    }

    BufferedImage newImage = newArgbBufferedImage(source.getWidth() + padding * 2,
            source.getHeight() + padding * 2);
    Graphics2D g = (Graphics2D) newImage.getGraphics();
    g.drawImage(source, padding, padding, null);
    return newImage;
}

From source file:contactangle.ImageControl.java

public static BufferedImage copyByPixel(BufferedImage ii) {
    BufferedImage oi = new BufferedImage(ii.getWidth(), ii.getHeight(), BufferedImage.TYPE_INT_RGB);
    for (int x = 0; x < ii.getWidth(); x++) {
        for (int y = 0; y < ii.getHeight(); y++) {
            int pixelData = ii.getRGB(x, y);
            oi.setRGB(x, y, pixelData);//from   w  w  w  .  jav  a 2  s.co m
        }
    }
    return oi;
}

From source file:costumetrade.common.util.PdfUtils.java

public static PDDocument createImagePdf(File file) {

    PDPageContentStream contentStream = null;
    try {//  www  .j  av  a 2s .  c  o m
        BufferedImage bimg = ImageIO.read(file);
        PDDocument document = new PDDocument();
        PDPage page = new PDPage(new PDRectangle(bimg.getWidth(), bimg.getHeight()));
        document.addPage(page);
        PDImageXObject image = PDImageXObject.createFromFileByExtension(file, document);
        contentStream = new PDPageContentStream(document, page);
        contentStream.drawImage(image, 0, 0);
        return document;
    } catch (IOException e) {
        throw new RuntimeException("?PDF", e);
    } finally {
        IOUtils.closeQuietly(contentStream);
    }

}

From source file:Utils.java

/** 
 * Renders multiple paragraphs of text in an array to an image (created and returned). 
 *
 * @param font The font to use/*from  w ww .j a  v  a 2s  .c om*/
 * @param textColor The color of the text
 * @param text The message in an array of strings (one paragraph in each
 * @param width The width the text should be limited to
 * @return An image with the text rendered into it
 */
public static BufferedImage renderTextToImage(Font font, Color textColor, String text[], int width) {
    LinkedList<BufferedImage> images = new LinkedList<BufferedImage>();

    int totalHeight = 0;

    for (String paragraph : text) {
        BufferedImage paraImage = renderTextToImage(font, textColor, paragraph, width);
        totalHeight += paraImage.getHeight();
        images.add(paraImage);
    }

    BufferedImage image = createCompatibleImage(width, totalHeight);
    Graphics2D graphics = (Graphics2D) image.createGraphics();

    int y = 0;

    for (BufferedImage paraImage : images) {
        graphics.drawImage(paraImage, 0, y, null);
        y += paraImage.getHeight();
    }

    graphics.dispose();
    return image;
}

From source file:com.fun.util.TesseractUtil.java

/**
 * //from w w  w  .  ja va 2  s . co m
 *
 * @param imageFile
 * @param times
 * @param targetFile
 * @throws IOException
 */
private static void scaled(File imageFile, int times, File targetFile) throws IOException {
    BufferedImage image = ImageIO.read(imageFile);
    int targetWidth = image.getWidth() * times;
    int targetHeight = image.getHeight() * times;
    int type = (image.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB
            : BufferedImage.TYPE_INT_ARGB;
    BufferedImage tmp = new BufferedImage(targetWidth, targetHeight, type);
    Graphics2D g2 = tmp.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2.drawImage(image, 0, 0, targetWidth, targetHeight, null);
    g2.dispose();
    ImageIO.write(tmp, "png", targetFile);
}

From source file:Main.java

/**
 * Rotates given image by given degrees which should be a multiple of 90
 * @param source image to be rotated/*  www . ja v  a 2 s.  c  o m*/
 * @param degrees the angle by which to rotate, should be a multiple of 90
 * @return the rotated image
 */
public static BufferedImage rotateByRightAngle(BufferedImage source, int degrees) {
    assert degrees % 90 == 0;
    degrees = degrees % 360;

    int w = source.getWidth();
    int h = source.getHeight();
    int w1, h1;
    switch (degrees) {
    case 90:
    case 270:
        w1 = h;
        h1 = w;
        break;
    default:
        w1 = w;
        h1 = h;
    }
    BufferedImage rotated = new BufferedImage(w1, h1, source.getType());

    for (int x = 0; x < w; x++) {
        for (int y = 0; y < h; y++) {
            int v = source.getRGB(x, y);
            int x1, y1;
            switch (degrees) {
            case 90:
                x1 = h - y - 1;
                y1 = x;
                break;
            case 180:
                x1 = w - x - 1;
                y1 = h - y - 1;
                break;
            case 270:
                x1 = y;
                y1 = w - x - 1;
                break;
            default:
                x1 = x;
                y1 = y;
                break;
            }

            rotated.setRGB(x1, y1, v);
        }
    }

    return rotated;
}