List of usage examples for java.awt.image BufferedImage getHeight
public int getHeight()
From source file:com.l1j5.web.common.utils.ImageUtils.java
public static void getImageThumbnail(BufferedInputStream stream_file, String save, String type, int w, int h) { try {// www. ja v a 2 s . com File file = new File(save); BufferedImage bi = ImageIO.read(stream_file); int width = bi.getWidth(); int height = bi.getHeight(); if (w < width) { width = w; } if (h < height) { height = h; } BufferedImage bufferIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Image atemp = bi.getScaledInstance(width, height, Image.SCALE_AREA_AVERAGING); Graphics2D g2 = bufferIm.createGraphics(); g2.drawImage(atemp, 0, 0, width, height, null); ImageIO.write(bufferIm, type, file); } catch (Exception e) { log.error(e); } }
From source file:com.l1j5.web.common.utils.ImageUtils.java
public static void getImageThumbnail(BufferedInputStream stream_file, String save, String type, int w) { try {/*w ww . j ava 2 s .co m*/ File file = new File(save); BufferedImage bi = ImageIO.read(stream_file); int width = bi.getWidth(); int height = bi.getHeight(); double ratio = (double) height / width; height = (int) (w * ratio); if (w < width) { width = w; } BufferedImage bufferIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Image atemp = bi.getScaledInstance(width, height, Image.SCALE_AREA_AVERAGING); Graphics2D g2 = bufferIm.createGraphics(); g2.drawImage(atemp, 0, 0, width, height, null); ImageIO.write(bufferIm, type, file); } catch (Exception e) { log.error(e); } }
From source file:Main.java
private static void applyShadow(BufferedImage image, int shadowSize, Color shadowColor, float shadowOpacity) { int dstWidth = image.getWidth(); int dstHeight = image.getHeight(); int left = (shadowSize - 1) >> 1; int right = shadowSize - left; int xStart = left; int xStop = dstWidth - right; int yStart = left; int yStop = dstHeight - right; int shadowRgb = shadowColor.getRGB() & 0x00FFFFFF; int[] aHistory = new int[shadowSize]; int historyIdx = 0; int aSum;/* w w w . j a va 2 s.c o m*/ int[] dataBuffer = ((DataBufferInt) image.getRaster().getDataBuffer()).getData(); int lastPixelOffset = right * dstWidth; float sumDivider = shadowOpacity / shadowSize; // horizontal pass for (int y = 0, bufferOffset = 0; y < dstHeight; y++, bufferOffset = y * dstWidth) { aSum = 0; historyIdx = 0; for (int x = 0; x < shadowSize; x++, bufferOffset++) { int a = dataBuffer[bufferOffset] >>> 24; aHistory[x] = a; aSum += a; } bufferOffset -= right; for (int x = xStart; x < xStop; x++, bufferOffset++) { int a = (int) (aSum * sumDivider); dataBuffer[bufferOffset] = a << 24 | shadowRgb; // substract the oldest pixel from the sum aSum -= aHistory[historyIdx]; // get the lastest pixel a = dataBuffer[bufferOffset + right] >>> 24; aHistory[historyIdx] = a; aSum += a; if (++historyIdx >= shadowSize) { historyIdx -= shadowSize; } } } // vertical pass for (int x = 0, bufferOffset = 0; x < dstWidth; x++, bufferOffset = x) { aSum = 0; historyIdx = 0; for (int y = 0; y < shadowSize; y++, bufferOffset += dstWidth) { int a = dataBuffer[bufferOffset] >>> 24; aHistory[y] = a; aSum += a; } bufferOffset -= lastPixelOffset; for (int y = yStart; y < yStop; y++, bufferOffset += dstWidth) { int a = (int) (aSum * sumDivider); dataBuffer[bufferOffset] = a << 24 | shadowRgb; // substract the oldest pixel from the sum aSum -= aHistory[historyIdx]; // get the lastest pixel a = dataBuffer[bufferOffset + lastPixelOffset] >>> 24; aHistory[historyIdx] = a; aSum += a; if (++historyIdx >= shadowSize) { historyIdx -= shadowSize; } } } }
From source file:eu.europa.esig.dss.pades.signature.visible.ImageFactory.java
/** * This method returns the image size with the original parameters (the generation uses DPI) * @param imageParameters the image parameters * @return a Dimension object//from w w w .ja v a 2 s. c om * @throws IOException */ public static Dimension getOptimalSize(SignatureImageParameters imageParameters) throws IOException { int width = 0; int height = 0; if (imageParameters.getImage() != null) { BufferedImage image = ImageIO.read(imageParameters.getImage()); width = image.getWidth(); height = image.getHeight(); } SignatureImageTextParameters textParamaters = imageParameters.getTextParameters(); if ((textParamaters != null) && StringUtils.isNotEmpty(textParamaters.getText())) { Dimension textDimension = ImageTextWriter.computeSize(textParamaters.getFont(), textParamaters.getText()); switch (textParamaters.getSignerNamePosition()) { case LEFT: case RIGHT: width += textDimension.width; height = Math.max(height, textDimension.height); break; case TOP: case BOTTOM: width = Math.max(width, textDimension.width); height += textDimension.height; break; default: break; } } return new Dimension(width, height); }
From source file:de.bamamoto.mactools.png2icns.Scaler.java
public static BufferedImage resize(BufferedImage source, int width, int height) { double xScale = ((double) width) / (double) source.getWidth(); double yScale = ((double) height) / (double) source.getHeight(); BufferedImage result = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration()/*from w w w.j a va 2s . com*/ .createCompatibleImage(width, height, source.getColorModel().getTransparency()); Graphics2D newImage = null; try { newImage = result.createGraphics(); newImage.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); newImage.drawRenderedImage(source, AffineTransform.getScaleInstance(xScale, yScale)); } finally { if (newImage != null) { newImage.dispose(); } } return result; }
From source file:com.jaeksoft.searchlib.util.ImageUtils.java
public static final boolean checkIfManyColors(BufferedImage image) { int w = image.getWidth(); int h = image.getHeight(); if (w == 0 && h == 0) return false; int unicolor = image.getRGB(0, 0); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int pixel = image.getRGB(x, y); if (pixel != unicolor) return true; }//from www. j a va 2 s .co m } return false; }
From source file:CursorUtil.java
public static Cursor createCursor(BufferedImage img, Point hotspot, String name) throws IndexOutOfBoundsException, Exception { Toolkit tk = Toolkit.getDefaultToolkit(); Dimension d = tk.getBestCursorSize(img.getWidth(), img.getHeight()); if ((d.width == img.getWidth()) && (d.height == img.getHeight())) return tk.createCustomCursor(img, hotspot, name); if ((d.width + d.height) < 2) throw new Exception("Invalid Size"); BufferedImage newImg = GraphicsUtil.createImage(d.width, d.height); Graphics2D g2 = newImg.createGraphics(); g2.drawImage(img, // what to draw 0, // dest left 0, // dest top newImg.getWidth(), // dest right newImg.getHeight(), // dest bottom 0, // src left 0, // src top img.getWidth(), // src right img.getHeight(), // src bottom null // to notify of image updates );//from ww w . java 2 s. com return tk.createCustomCursor(newImg, hotspot, name); }
From source file:com.ttech.cordovabuild.domain.application.source.ApplicationSourceFactoryImpl.java
public static BufferedImage scaleTo(BufferedImage image, Integer height, Integer width) throws IOException { int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); double scaleX = (double) (width == null ? 1 : width / imageWidth); double scaleY = (double) (height == null ? 1 : height / imageHeight); AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY); AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR); return bilinearScaleOp.filter(image, new BufferedImage(width, height, image.getType())); }
From source file:com.github.lucapino.sheetmaker.PreviewJFrame.java
public static BufferedImage makeRoundedCorner(BufferedImage image, int cornerRadius) { int w = image.getWidth(); int h = image.getHeight(); BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = output.createGraphics(); // This is what we want, but it only does hard-clipping, i.e. aliasing // g2.setClip(new RoundRectangle2D ...) // so instead fake soft-clipping by first drawing the desired clip shape // in fully opaque white with antialiasing enabled... g2.setComposite(AlphaComposite.Src); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.WHITE);/*from w w w . j a va 2 s . c o m*/ g2.fill(new RoundRectangle2D.Float(0, 0, w, h, cornerRadius, cornerRadius)); // ... then compositing the image on top, // using the white shape from above as alpha source g2.setComposite(AlphaComposite.SrcIn); g2.drawImage(image, 0, 0, null); g2.dispose(); return output; }
From source file:ImageClip.java
/** * Clips the input image to the specified shape * //from w w w . j a v a 2s .c om * @param image * the input image * @param clipVerts * list of x, y pairs defining the clip shape, normalised * to image dimensions (think texture coordinates) * @return The smallest image containing those pixels that fall * inside the clip shape */ public static BufferedImage clip(BufferedImage image, float... clipVerts) { assert clipVerts.length >= 6; assert clipVerts.length % 2 == 0; int[] xp = new int[clipVerts.length / 2]; int[] yp = new int[xp.length]; int minX = image.getWidth(), minY = image.getHeight(), maxX = 0, maxY = 0; for (int j = 0; j < xp.length; j++) { xp[j] = Math.round(clipVerts[2 * j] * image.getWidth()); yp[j] = Math.round(clipVerts[2 * j + 1] * image.getHeight()); minX = Math.min(minX, xp[j]); minY = Math.min(minY, yp[j]); maxX = Math.max(maxX, xp[j]); maxY = Math.max(maxY, yp[j]); } for (int i = 0; i < xp.length; i++) { xp[i] -= minX; yp[i] -= minY; } Polygon clip = new Polygon(xp, yp, xp.length); BufferedImage out = new BufferedImage(maxX - minX, maxY - minY, image.getType()); Graphics g = out.getGraphics(); g.setClip(clip); g.drawImage(image, -minX, -minY, null); g.dispose(); return out; }