List of usage examples for java.awt.image BufferedImage getWidth
public int getWidth()
From source file:Main.java
public static BufferedImage scaleImage(BufferedImage img, int width, int height, Color background) { int imgWidth = img.getWidth(); int imgHeight = img.getHeight(); if (imgWidth * height < imgHeight * width) { width = imgWidth * height / imgHeight; } else {// www. j a va2 s . c o m height = imgHeight * width / imgWidth; } BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = newImage.createGraphics(); try { g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g.setBackground(background); g.clearRect(0, 0, width, height); g.drawImage(img, 0, 0, width, height, null); } finally { g.dispose(); } return newImage; }
From source file:Main.java
protected static boolean testNeighbour(BufferedImage source, int x, int y, boolean alpha) { if (x >= 0 && y >= 0 && x < source.getWidth() && y < source.getHeight()) { int gray = source.getRGB(x, y) & 0x000000ff; int alphaI = (source.getRGB(x, y) & 0xff000000) >>> 24; return (alpha && alphaI == 0) || (!alpha && gray == 255); }//from ww w. j a va2 s . c o m return true; }
From source file:com.cisco.surf.jenkins.plugins.jenkow.tests.DiagramGeneration.DiagramTest.java
private static String getGeo(BufferedImage img) { return img.getWidth() + "x" + img.getHeight(); }
From source file:Transparency.java
public static BufferedImage makeImageTranslucent(BufferedImage source, double alpha) { BufferedImage target = new BufferedImage(source.getWidth(), source.getHeight(), java.awt.Transparency.TRANSLUCENT); // Get the images graphics Graphics2D g = target.createGraphics(); // Set the Graphics composite to Alpha g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) alpha)); // Draw the image into the prepared reciver image g.drawImage(source, null, 0, 0);/*w ww. j a v a 2s .c om*/ // let go of all system resources in this Graphics g.dispose(); // Return the image return target; }
From source file:Main.java
/** * Creates a shadow mask//from w ww . ja va2s.co m * @param image * @param shadowColor * @param shadowOpacity * @return */ private static BufferedImage createShadowMask(BufferedImage image, Color shadowColor, float shadowOpacity) { BufferedImage mask = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = mask.createGraphics(); g2d.drawImage(image, 0, 0, null); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN, shadowOpacity)); g2d.setColor(shadowColor); g2d.fillRect(0, 0, image.getWidth(), image.getHeight()); g2d.dispose(); return mask; }
From source file:Main.java
/** * Applies a {@link BufferedImageOp} on the given {@link BufferedImage}. * * @param source The source image.//from w w w . j av a2 s. co m * @param op The operation to perform. * @return A new image with the operation performed. */ public static BufferedImage operatedImage(BufferedImage source, BufferedImageOp op) { BufferedImage newImage = newArgbBufferedImage(source.getWidth(), source.getHeight()); Graphics2D g = (Graphics2D) newImage.getGraphics(); g.drawImage(source, op, 0, 0); return newImage; }
From source file:Main.java
/** * Fills the given {@link BufferedImage} with a {@link Paint}, preserving its alpha channel. * * @param source The source image.// ww w .jav a 2 s. co m * @param paint The paint to fill with. * @return A new, painted/filled image. */ public static BufferedImage filledImage(BufferedImage source, Paint paint) { BufferedImage newImage = newArgbBufferedImage(source.getWidth(), source.getHeight()); Graphics2D g = (Graphics2D) newImage.getGraphics(); g.drawImage(source, 0, 0, null); g.setComposite(AlphaComposite.SrcAtop); g.setPaint(paint); g.fillRect(0, 0, source.getWidth(), source.getHeight()); return newImage; }
From source file:Main.java
/** * This method cleans input image by replacing * all non black pixels with white pixels * @param image - input image that will be cleaned * @return - cleaned input image as BufferedImage *//*from w w w . j av a 2 s . co m*/ public static BufferedImage blackAndWhiteCleaning(BufferedImage image) { for (int j = 0; j < image.getHeight(); j++) { for (int i = 0; i < image.getWidth(); i++) { if (image.getRGB(i, j) != -16777216) { image.setRGB(i, j, -1); } } } return image; }
From source file:Main.java
/** * Quickly copies an image./*from w w w .ja v a2s .c o m*/ * @param src The source image. * @return The replicated image. */ public static BufferedImage imgUtilFastCopy(BufferedImage src) { if (src == null) return null; BufferedImage b = new BufferedImage(src.getWidth(), src.getHeight(), src.getType()); b.setData(src.getRaster()); return b; }
From source file:Main.java
public static double meanValue(BufferedImage image) { Raster raster = image.getRaster(); double sum = 0.0; for (int y = 0; y < image.getHeight(); ++y) { for (int x = 0; x < image.getWidth(); ++x) { sum += raster.getSample(x, y, 0); }// w w w .j av a 2 s. c o m } return sum / (image.getWidth() * image.getHeight()); }