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:main.MapKit.java

private BufferedImage convert(BufferedImage loadImg, Color newColor) {
    int w = loadImg.getWidth();
    int h = loadImg.getHeight();
    BufferedImage imgOut = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    BufferedImage imgColor = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

    Graphics2D g = imgColor.createGraphics();
    g.setColor(newColor);/*from ww  w.ja v  a  2s . c  om*/
    g.fillRect(0, 0, w + 1, h + 1);
    g.dispose();

    Graphics2D graphics = imgOut.createGraphics();
    graphics.drawImage(loadImg, 0, 0, null);
    graphics.setComposite(MultiplyComposite.Default);
    graphics.drawImage(imgColor, 0, 0, null);
    graphics.dispose();

    return imgOut;
}

From source file:cpcc.ros.services.RosImageConverterTest.java

/**
 * @param image the image to be checked.
 *//*w  w w .j  a va2  s  .  c o m*/
private void assertThatImageIsEmpty(BufferedImage image) {
    for (int y = 0; y < image.getHeight(); ++y) {
        for (int x = 0; x < image.getWidth(); ++x) {
            assertThat(image.getRGB(x, y)).overridingErrorMessage("Problem at x=%d, y=%d", x, y).isEqualTo(0);
        }
    }
}

From source file:org.iish.visualmets.services.ImageTransformation.java

/**
 * Returns a 90 degrees rotated image/*from   w  ww  .j ava 2  s.  c  o  m*/
 *
 * @param bi image
 * @return a rotated image
 */
private BufferedImage RotateImage90Degrees(BufferedImage bi) {
    int width = bi.getWidth();
    int height = bi.getHeight();

    BufferedImage biFlip = new BufferedImage(height, width, bi.getType());

    for (int i = 0; i < width; i++)
        for (int j = 0; j < height; j++) {
            biFlip.setRGB(height - 1 - j, i, bi.getRGB(i, j));
        }

    return biFlip;
}

From source file:org.iish.visualmets.services.ImageTransformation.java

/**
 * Returns a 180 degrees rotated image/*  www  . j  a v a  2s.c om*/
 *
 * @param bi image
 * @return a rotated image
 */
private BufferedImage RotateImage180Degrees(BufferedImage bi) {
    int width = bi.getWidth();
    int height = bi.getHeight();

    BufferedImage biFlip = new BufferedImage(width, height, bi.getType());

    for (int i = 0; i < width; i++)
        for (int j = 0; j < height; j++) {
            biFlip.setRGB(width - 1 - i, height - 1 - j, bi.getRGB(i, j));
        }

    return biFlip;
}

From source file:org.iish.visualmets.services.ImageTransformation.java

/**
 * Returns a 270 degrees rotated image//ww  w .j a  va 2s  .  c om
 *
 * @param bi image
 * @return a rotated image
 */
private BufferedImage RotateImage270Degrees(BufferedImage bi) {
    int width = bi.getWidth();
    int height = bi.getHeight();

    BufferedImage biFlip = new BufferedImage(height, width, bi.getType());

    for (int i = 0; i < width; i++)
        for (int j = 0; j < height; j++) {
            biFlip.setRGB(j, width - 1 - i, bi.getRGB(i, j));
        }

    return biFlip;
}

From source file:com.sketchy.server.ImageUploadServlet.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    JSONServletResult jsonServletResult = new JSONServletResult(Status.SUCCESS);
    try {/*from   w w  w  .j  a v  a2s .co  m*/

        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
        if (isMultipart) {

            DiskFileItemFactory factory = new DiskFileItemFactory();
            factory.setRepository(FileUtils.getTempDirectory());
            factory.setSizeThreshold(MAX_SIZE);

            ServletFileUpload servletFileUpload = new ServletFileUpload(factory);
            List<FileItem> files = servletFileUpload.parseRequest(request);
            for (FileItem fileItem : files) {
                String uploadFileName = fileItem.getName();
                if (StringUtils.isNotBlank(uploadFileName)) {
                    // Don't allow \\ in the filename, assume it's a directory separator and convert to "/"
                    // and take the filename after the last "/"
                    // This will fix the issue of Jetty not reading and serving files
                    // with "\" (%5C) characters 
                    // This also fixes the issue of IE sometimes sending the whole path 
                    // (depending on the security settings)
                    uploadFileName = StringUtils.replaceChars(uploadFileName, "\\", "/");
                    if (StringUtils.contains(uploadFileName, "/")) {
                        uploadFileName = StringUtils.substringAfterLast(uploadFileName, "/");
                    }

                    File uploadFile = HttpServer.getUploadFile(uploadFileName);
                    // make sure filename is actually in the upload directory
                    // we don't want any funny games
                    if (!uploadFile.getParentFile().equals(HttpServer.IMAGE_UPLOAD_DIRECTORY)) {
                        throw new RuntimeException("Can not upload File. Invalid directory!");
                    }

                    // if saved ok, then need to add the data file
                    SourceImageAttributes sourceImageAttributes = new SourceImageAttributes();
                    sourceImageAttributes.setImageName(uploadFileName);

                    File pngFile = HttpServer.getUploadFile(sourceImageAttributes.getImageFilename());
                    if (pngFile.exists()) {
                        throw new Exception(
                                "Can not Upload file. File '" + uploadFileName + "' already exists!");
                    }
                    File dataFile = HttpServer.getUploadFile(sourceImageAttributes.getDataFilename());

                    // Convert the image to a .PNG file
                    BufferedImage image = ImageUtils.loadImage(fileItem.getInputStream());
                    ImageUtils.saveImage(pngFile, image);

                    sourceImageAttributes.setWidth(image.getWidth());
                    sourceImageAttributes.setHeight(image.getHeight());

                    FileUtils.writeStringToFile(dataFile, sourceImageAttributes.toJson());
                    jsonServletResult.put("imageName", uploadFileName);
                }
            }
        }
    } catch (Exception e) {
        jsonServletResult = new JSONServletResult(Status.ERROR, e.getMessage());
    }
    response.setContentType("text/html");
    response.setStatus(HttpServletResponse.SC_OK);
    response.getWriter().print(jsonServletResult.toJSONString());
}

From source file:net.sqs2.omr.result.export.chart.ChartImageWriter.java

private void setSectionPaint(PieDataset dataSet, PiePlot piePlot) {
    Paint outlinePaint = Color.BLACK;
    Stroke outlineStroke = new BasicStroke(1.0f);

    if (this.itemBackgroundImages != null && 0 < this.itemBackgroundImages.length) {
        int index = 0;
        for (Object key : dataSet.getKeys()) {
            int imageIndex = index % this.itemBackgroundImages.length;
            BufferedImage texture = this.itemBackgroundImages[imageIndex];
            Rectangle2D anchor = new Rectangle2D.Double(0, 0, texture.getWidth(), texture.getHeight());
            TexturePaint fillPaint = new TexturePaint(texture, anchor);
            piePlot.setSectionPaint((Comparable<?>) key, fillPaint);
            piePlot.setSectionOutlinePaint((Comparable<?>) key, outlinePaint);
            piePlot.setSectionOutlineStroke((Comparable<?>) key, outlineStroke);
            index++;/* w  ww  . j  a va2  s . co m*/
        }
    }
    piePlot.setOutlineVisible(true);
    piePlot.setOutlinePaint(outlinePaint);
    piePlot.setOutlineStroke(outlineStroke);
    piePlot.setSectionOutlinesVisible(true);
    piePlot.setBaseSectionOutlinePaint(outlinePaint);
    piePlot.setBaseSectionOutlineStroke(outlineStroke);
}

From source file:com.tascape.qa.th.android.driver.AdbDevice.java

private boolean bufferedImagesEqual(BufferedImage img1, BufferedImage img2) {
    if (img1.getWidth() != img2.getWidth() || img1.getHeight() != img2.getHeight()) {
        return false;
    }//from  w  ww  .  j ava2 s.com

    boolean equal = true;
    for (int x = 100; x < img1.getWidth() - 100; x++) {
        for (int y = 100; y < img1.getHeight() - 100; y++) {
            if (img1.getRGB(x, y) != img2.getRGB(x, y)) {
                equal = false;
            }
        }
    }
    return equal;
}

From source file:net.malisis.advert.advert.Advert.java

protected void loadFile() {
    if (file == null || !file.exists())
        return;//w ww  .j  av  a 2s  . co m

    size = file.length();
    BufferedImage img;
    try {
        img = ImageIO.read(new ByteArrayInputStream(Files.toByteArray(file)));
        if (img != null) {
            width = img.getWidth();
            height = img.getHeight();
        }
    } catch (IOException e) {
        MalisisAdvert.log.error("Could not get image infos for {}", this, e);
    }
}