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:edworld.pdfreader4humans.PDFReaderTest.java

private void assertImagesAreSimilar(InputStream expectedOutputStream, BufferedImage outputImage)
        throws IOException {
    try {//from   w  ww  . ja  v  a  2s .  c o m
        BufferedImage expectedOutputImage = ImageIO.read(expectedOutputStream);
        assertEquals(expectedOutputImage.getType(), outputImage.getType());
        assertEquals(expectedOutputImage.getWidth(), outputImage.getWidth());
        assertEquals(expectedOutputImage.getHeight(), outputImage.getHeight());
        assertEquals(expectedOutputImage.getTransparency(), outputImage.getTransparency());
        for (int k = 0; k < Math.max(outputImage.getWidth(), outputImage.getHeight()); k++) {
            int kX = k % outputImage.getWidth();
            int kY = k % outputImage.getHeight();
            int expectedColor = expectedOutputImage.getRGB(kX, kY);
            int actualColor = outputImage.getRGB(kX, kY);
            if ((expectedColor ^ 0xFFFFFF) == actualColor)
                expectedColor ^= 0xFFFFFF;
            assertEquals("Color should be the same at (" + k + "," + k + ").", expectedColor, actualColor);
        }
    } finally {
        expectedOutputStream.close();
    }
}

From source file:Textures.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;

    g2d.setColor(new Color(212, 212, 212));
    g2d.drawRect(10, 15, 90, 60);//w w  w  .  j  av a  2  s.c  om

    BufferedImage bimage1 = null;

    URL url1 = ClassLoader.getSystemResource("a.png");

    try {
        bimage1 = ImageIO.read(url1);
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

    Rectangle rect1 = new Rectangle(0, 0, bimage1.getWidth(), bimage1.getHeight());
    TexturePaint texture1 = new TexturePaint(bimage1, rect1);

    g2d.setPaint(texture1);
    g2d.fillRect(10, 15, 90, 60);
}

From source file:eu.novait.imagerenamer.model.ImageFile.java

private void createThumbnail() {
    try {/*  ww w  . jav  a2s .co  m*/
        BufferedImage tmp = ImageIO.read(this.filepath);
        int tmpW = tmp.getWidth();
        int tmpH = tmp.getHeight();
        double ratio = (double) tmpW / (double) tmpH;
        int w = 400;
        int h = (int) Math.round(w / ratio);
        BufferedImage bi = getCompatibleImage(w, h);
        Graphics2D g2d = bi.createGraphics();
        double xScale = (double) w / tmp.getWidth();
        double yScale = (double) h / tmp.getHeight();
        AffineTransform at = AffineTransform.getScaleInstance(xScale, yScale);
        g2d.drawRenderedImage(tmp, at);
        g2d.dispose();
        this.setThumbnail(bi);
    } catch (IOException ex) {
        Logger.getLogger(ImageFile.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:gr.iti.mklab.reveal.forensics.util.Util.java

public static BufferedImage scaleImage(BufferedImage image, int width, int height) {
    assert (width > 0 && height > 0);
    // create image of new size
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics g = img.getGraphics();
    ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_INTERPOLATION,
            RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
    //  ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.drawImage(image, 0, 0, img.getWidth(), img.getHeight(), null);
    return img;/*from  w  w w. j a  va2  s  .  c o  m*/
}

From source file:maltcms.ui.fileHandles.serialized.SeriesPaintComboBoxRenderer.java

private BufferedImage createColorImage(Paint p) {
    BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = bi.createGraphics();
    g2.setPaint(p);// w  ww  . j a v  a  2 s . c om
    g2.fillRect(0, 0, bi.getWidth(), bi.getHeight());
    return bi;
}

From source file:gr.iti.mklab.reveal.forensics.maps.dwnoisevar.DWNoiseVarExtractor.java

public void getNoiseMap() throws IOException {

    BufferedImage img = inputImage;

    int imWidth, imHeight;
    if (img.getWidth() % 2 == 0) {
        imWidth = img.getWidth();/* w  ww  .  ja  v  a2 s.  co m*/
    } else {
        imWidth = (img.getWidth() - 1);
    }
    if (img.getHeight() % 2 == 0) {
        imHeight = img.getHeight();
    } else {
        imHeight = (img.getHeight() - 1);
    }

    int columnFilterScale = (int) (Math.log(imHeight) / Math.log(2)) - 1;
    int rowFilterScale = (int) (Math.log(imWidth) / Math.log(2)) - 1;

    double[][] imgYAsArray = new double[imWidth][imHeight];
    double[][] filteredImgYAsArray = new double[imWidth][imHeight / 2];
    double[][] doubleFilteredImgYAsArray = new double[imWidth / 2][imHeight / 2];
    double[] imgColumn, imgRow;
    Color tmpcolor;
    double R, G, B;

    for (int ii = 0; ii < imWidth; ii++) {
        for (int jj = 0; jj < imHeight; jj++) {
            tmpcolor = new Color(img.getRGB(ii, jj));
            R = tmpcolor.getRed();
            G = tmpcolor.getGreen();
            B = tmpcolor.getBlue();
            imgYAsArray[ii][jj] = 0.2989 * R + 0.5870 * G + 0.1140 * B;
        }
    }

    double[] waveletColumn;
    RealMatrix rm = new Array2DRowRealMatrix(imgYAsArray);
    for (int ii = 0; ii < imWidth; ii++) {
        try {
            imgColumn = new double[imHeight];
            imgColumn = rm.getRow(ii);
            //Long startTime1 = System.currentTimeMillis();  
            waveletColumn = DWT.transform(imgColumn, Wavelet.Daubechies, 8, columnFilterScale,
                    DWT.Direction.forward);
            System.arraycopy(waveletColumn, imHeight / 2, filteredImgYAsArray[ii], 0, imHeight / 2);
        } catch (Exception ex) {
            Logger.getLogger(DWNoiseVarExtractor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    double[] waveletRow;
    RealMatrix rm2 = new Array2DRowRealMatrix(filteredImgYAsArray);
    for (int jj = 0; jj < imHeight / 2; jj++) {
        try {
            imgRow = new double[imWidth];
            imgRow = rm2.getColumn(jj);
            waveletRow = DWT.transform(imgRow, Wavelet.Daubechies, 8, rowFilterScale, DWT.Direction.forward);
            for (int ii = 0; ii < imWidth / 2; ii++) {
                doubleFilteredImgYAsArray[ii][jj] = waveletRow[ii + imWidth / 2];
            }
        } catch (Exception ex) {
            Logger.getLogger(DWNoiseVarExtractor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    int blockSize = 8;
    double[][] blockNoiseVar = Util.blockNoiseVar(doubleFilteredImgYAsArray, blockSize);

    int medianFilterSize = 7;
    if (medianFilterSize > blockNoiseVar.length) {
        medianFilterSize = blockNoiseVar.length - 1;
    }
    if (medianFilterSize > blockNoiseVar[0].length) {
        medianFilterSize = blockNoiseVar[0].length - 1;
    }
    if (medianFilterSize < 5) {
        minNoiseValue = 0;
        maxNoiseValue = 0;
        noiseMap = new float[1][1];
        noiseMap[0][0] = 0;
        double[][] artificialOutput = new double[1][1];
        artificialOutput[0][0] = 0;
        BufferedImage outputImage = Util.visualizeWithJet(artificialOutput);
        displaySurface = outputImage;
        return;
    }

    float[][] outBlockMap = Util.medianFilterSingleChannelImage(blockNoiseVar, medianFilterSize);

    minNoiseValue = Util.minDouble2DArray(outBlockMap);
    maxNoiseValue = Util.maxDouble2DArray(outBlockMap);
    noiseMap = outBlockMap;
    double[][] normalizedMap = Util.normalizeIm(outBlockMap);
    BufferedImage outputImage = Util.visualizeWithJet(normalizedMap);
    // output
    displaySurface = outputImage;
}

From source file:DBScan.java

private double eucDistance(BufferedImage img1, BufferedImage img2) {
    double distance = 0;
    for (int x = 0; x < Math.max(img1.getWidth(), img2.getWidth()); x++)
        for (int y = 0; y < Math.max(img1.getHeight(), img2.getHeight()); y++) {
            distance += minDistance(x, y, img1, img2);
            distance += minDistance(x, y, img2, img1);

            if (distance > epsSqr + 1)
                break;
        }//from w  w w . j a  v a  2s  .com
    distance = Math.sqrt(distance);

    return distance;
}

From source file:contactangle.ImageControl.java

public void setImage(BufferedImage img) {
    this.img = applyEdgeDetect(img);

    if (img != null)
        setPreferredSize(new Dimension(img.getWidth(), img.getHeight()));
    else//from   w w w .j  av a  2s  . c o  m
        setPreferredSize(new Dimension(200, 50));
}

From source file:de.anycook.upload.UploadHandler.java

/**
 * speichert eine grosse Version des Bildes
 *
 * @param image    BufferedImage/*  ww  w .  j a va  2 s. c om*/
 * @param filename Name der zu erzeugenden Datei
 */
private void saveOriginalImage(BufferedImage image, String filename) throws IOException {
    int height = image.getHeight();
    int width = image.getWidth();

    BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    newImage.getGraphics().drawImage(image, 0, 0, null);

    imageSaver.save("original/", filename, newImage);

}

From source file:io.gameover.utilities.pixeleditor.Frame.java

public BufferedImage getAsBufferedImage(Color transparent) {
    BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
    for (int i = 0; i < bi.getWidth(); i++) {
        for (int j = 0; j < bi.getHeight(); j++) {
            if (transparent != null && argb[i][j] == NO_COLOR_AS_INT) {
                bi.setRGB(i, j, transparent.getRGB());
            } else {
                bi.setRGB(i, j, argb[i][j]);
            }//from  w  w w .j  ava 2 s . c  om
        }
    }
    return bi;
}