List of usage examples for java.awt.image BufferedImage getHeight
public int 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);/*from w w w . ja v a 2 s .c o m*/ // let go of all system resources in this Graphics g.dispose(); // Return the image return target; }
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 {/*w w w.jav a 2 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
/** * Applies a {@link BufferedImageOp} on the given {@link BufferedImage}. * * @param source The source image.// w ww.ja va 2s . c o 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
/** * Quickly copies an image.//w w w . j a v a2 s .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
/** * Fills the given {@link BufferedImage} with a {@link Paint}, preserving its alpha channel. * * @param source The source image.// w w w.j a va 2 s . c om * @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
/** * Shrinks an image to fit into memory more * Effectively.// w w w. j a v a 2 s. c o m * @param src The source image. * @return */ public static BufferedImage imgUtilMinimizeNoAlpha(BufferedImage src) { if (src == null) return null; BufferedImage b = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_3BYTE_BGR); Graphics2D g = (Graphics2D) b.getGraphics(); g.drawImage(src, 0, 0, null); g.dispose(); return b; }
From source file:GraphicsUtil.java
public static void drawCentered(Graphics g, BufferedImage img, Point2D location) { drawCentered(g, img, location, img.getWidth(), img.getHeight(), null); }
From source file:Main.java
public static int[] columnChecksums(BufferedImage img) { int[] sums = new int[img.getWidth()]; Arrays.fill(sums, 0);/*from ww w. ja v a2s.c o m*/ for (int y = 0; y < img.getHeight(); y++) { for (int x = 0; x < img.getWidth(); x++) { final int colour = img.getRGB(x, y); sums[x] += (int) ((colour & 0x00ff0000) >> 16); sums[x] += (int) ((colour & 0x0000ff00) >> 8); sums[x] += (int) (colour & 0x000000ff); } } for (int x = 0; x < img.getWidth(); x++) { sums[x] %= 256; } return sums; }
From source file:com.buddycloud.mediaserver.business.util.ImageUtils.java
public static BufferedImage cropMaximumSquare(BufferedImage img) { int smallerSide = img.getHeight() <= img.getWidth() ? img.getHeight() : img.getWidth(); int x = img.getWidth() - smallerSide; int y = img.getHeight() - smallerSide; final BufferedImage croppedImg = Scalr.crop(img, x, y, smallerSide, smallerSide); return croppedImg; }
From source file:org.web4thejob.web.util.MediaUtil.java
public static BufferedImage createThumbnail(BufferedImage img) { if (img.getHeight() <= THUMBNAIL_HEIGHT) return img; BufferedImage resizedImage = resize(img, Method.AUTOMATIC, Mode.FIT_TO_HEIGHT, THUMBNAIL_HEIGHT); img.flush();//from w w w . j a va2s. co m return resizedImage; }