List of usage examples for java.awt.image BufferedImage getWidth
public int getWidth()
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 ww .j ava 2 s . c o m * @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:imageprocessingproject.ImageHistogram.java
private static void createHistogram(BufferedImage image) { histogram = new double[256]; int height = image.getHeight(); int width = image.getWidth(); int sum = 0;//w ww. j av a2 s . c o m for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { int grayVal = getGrayValue(image.getRGB(i, j)); histogram[grayVal]++; sum++; } } for (int i = 0; i < 256; i++) { histogram[i] = histogram[i] / sum; } }
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.openkm.util.ImageUtils.java
/** * cloneImage/* w w w .j av a 2 s .c o m*/ */ public static BufferedImage clone(BufferedImage source) { BufferedImage img = new BufferedImage(source.getWidth(), source.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = img.getGraphics(); g.drawImage(source, 0, 0, null); g.dispose(); return img; }
From source file:imageprocessingproject.ImageHistogram.java
public static BufferedImage autoContrastImage(BufferedImage image) { createContrastLUT(image);/*from w ww. j av a2s . co m*/ int height = image.getHeight(); int width = image.getWidth(); int r, g, b; Color c; BufferedImage tempImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { c = new Color(image.getRGB(i, j)); r = (int) (255 * contrast_lut[c.getRed()]); g = (int) (255 * contrast_lut[c.getGreen()]); b = (int) (255 * contrast_lut[c.getBlue()]); tempImage.setRGB(i, j, new Color(r, g, b, c.getAlpha()).getRGB()); } } return tempImage; }
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 ww w .ja v a 2 s.co m*/ } return false; }
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);// w w w .jav a2 s . c om 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:com.smash.revolance.ui.model.helper.ImageHelper.java
public static boolean imgEquals(File imgRef, File img) throws IOException { if (isCached(imgRef, img)) { return getComparisons(imgRef).get(img).booleanValue(); } else if (isCached(img, imgRef)) { return getComparisons(img).get(imgRef).booleanValue(); } else {//from w ww . j a va 2 s .com BufferedImage refBI = ImageIO.read(imgRef); BufferedImage imgBi = ImageIO.read(img); int width = imgBi.getWidth(); int height = imgBi.getHeight(); if (refBI.getWidth() == width && refBI.getHeight() == height) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { int refIntensity = refBI.getRGB(x, y); int imgIntensity = imgBi.getRGB(x, y); if (refIntensity != imgIntensity) { getComparisons(imgRef).put(img, false); return false; } } } } getComparisons(imgRef).put(img, true); return true; } }
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 w ww. j a va2 s .co m return tk.createCustomCursor(newImg, hotspot, name); }
From source file:com.smash.revolance.ui.model.helper.ImageHelper.java
public static BufferedImage scaleImage(BufferedImage image, double widthPerCent, double heightPerCent) { int w = (int) (image.getWidth() * widthPerCent); int h = (int) (image.getHeight() * heightPerCent); int t = image.getType(); Image scaledImage = image.getScaledInstance(w, h, Image.SCALE_SMOOTH); BufferedImage newImg = new BufferedImage(w, h, t); newImg.getGraphics().drawImage(scaledImage, 0, 0, null); return newImg; }