List of usage examples for java.awt.image BufferedImage getWidth
public int getWidth()
From source file:net.sourceforge.subsonic.controller.CoverArtController.java
public static BufferedImage scale(BufferedImage image, int width, int height) { int w = image.getWidth(); int h = image.getHeight(); BufferedImage thumb = image;/*w ww . j a v a2 s . com*/ // For optimal results, use step by step bilinear resampling - halfing the size at each step. do { w /= 2; h /= 2; if (w < width) { w = width; } if (h < height) { h = height; } BufferedImage temp = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = temp.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.drawImage(thumb, 0, 0, temp.getWidth(), temp.getHeight(), null); g2.dispose(); thumb = temp; } while (w != width); return thumb; }
From source file:com.vaadin.testbench.screenshot.ImageUtil.java
/** * Crops the image to the given size starting at (0,0) * /*from www. ja va 2 s . c o m*/ * @param image * The image to crop * @param width * width in pixels * @param height * height in pixels */ private static BufferedImage cropImage(BufferedImage image, int width, int height) { if (image.getWidth() == width && image.getHeight() == height) { return image; } return image.getSubimage(0, 0, width, height); }
From source file:com.vaadin.testbench.screenshot.ImageUtil.java
/** * Check canvas sizes and resize images to same size * /*from w w w .jav a 2 s. c o m*/ * @return true/false */ public static boolean imagesSameSize(BufferedImage image1, BufferedImage image2) { return (image1.getWidth() == image2.getWidth() && image1.getHeight() == image2.getHeight()); }
From source file:com.tools.image.IMagicHelper.java
private static int[] getRectangle(String file) throws IOException { BufferedImage tmp = ImageIO.read(new File(file)); return new int[] { tmp.getWidth(), tmp.getHeight() }; }
From source file:net.cloudkit.relaxation.CaptchaTest.java
public static void clearBorder(BufferedImage image) { final int width = image.getWidth(); final int height = image.getHeight(); // image.getMinX() image.getMinY() // // ww w . j a v a 2 s . co m for (int x = 0; x < width; x++) { image.setRGB(x, 0, Color.WHITE.getRGB()); } // ? for (int y = 0; y < height; y++) { image.setRGB(width - 1, y, Color.WHITE.getRGB()); } // for (int x = 0; x < width; x++) { image.setRGB(x, height - 1, Color.WHITE.getRGB()); } // for (int y = 0; y < height; y++) { image.setRGB(0, y, Color.WHITE.getRGB()); } }
From source file:com.ables.pix.utility.PictureOps.java
public static BufferedImage tilt(BufferedImage image, double rotation) { double sin = Math.abs(Math.sin(getAngle())); double cos = Math.abs(Math.cos(getAngle())); int w = image.getWidth(), h = image.getHeight(); int neww = (int) Math.floor(w * cos + sin * h), newh = (int) Math.floor(h * cos + sin * w); GraphicsConfiguration gc = getDefaultConfiguration(); BufferedImage rotated = gc.createCompatibleImage(neww, newh); Graphics2D g = rotated.createGraphics(); g.translate((neww - w) / 2, (newh - h / 2)); g.rotate(getAngle(), w / 2, h / 2);//w w w .jav a 2 s. co m g.drawRenderedImage(image, null); g.dispose(); return rotated; }
From source file:it.smartcommunitylab.parking.management.web.manager.MarkerIconStorage.java
private static BufferedImage changeColor(BufferedImage image, Color mask, Color replacement) { BufferedImage destImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = destImage.createGraphics(); g.drawImage(image, null, 0, 0);/*from ww w . j a v a 2 s . com*/ g.dispose(); for (int i = 0; i < destImage.getWidth(); i++) { for (int j = 0; j < destImage.getHeight(); j++) { int destRGB = destImage.getRGB(i, j); if (matches(mask.getRGB(), destRGB)) { int rgbnew = getNewPixelRGB(replacement.getRGB(), destRGB); destImage.setRGB(i, j, rgbnew); } } } return destImage; }
From source file:com.silverpeas.util.ImageUtil.java
public static String[] getWidthAndHeight(InputStream image) { String[] result = new String[2]; try {/*from w w w . j ava2s. c o m*/ BufferedImage inputBuf = ImageIO.read(image); // calcul de la taille de la sortie double inputBufWidth = inputBuf.getWidth(); double inputBufHeight = inputBuf.getHeight(); String sWidth = Double.toString(inputBufWidth); String sHeight = Double.toString(inputBufHeight); result[0] = sWidth.substring(0, sWidth.indexOf('.')); result[1] = sHeight.substring(0, sHeight.indexOf('.')); return result; } catch (Exception e) { if (image != null) { SilverTrace.error("util", "ImageUtil.getWidthAndHeightByHeight", "root.MSG_GEN_ERROR", e); } } result[0] = ""; result[1] = ""; return result; }
From source file:net.sf.mcf2pdf.mcfelements.util.ImageUtil.java
/** * Rotates the given buffered image by the given angle, and returns a newly * created image, containing the rotated image. * * @param img Image to rotate.//w w w. j a v a 2 s. c o m * @param angle Angle, in radians, by which to rotate the image. * @param drawOffset Receives the offset which is required to draw the image, * relative to the original (0,0) corner, so that the center of the image is * still on the same position. * * @return A newly created image containing the rotated image. */ public static BufferedImage rotateImage(BufferedImage img, float angle, Point drawOffset) { int w = img.getWidth(); int h = img.getHeight(); AffineTransform tf = AffineTransform.getRotateInstance(angle, w / 2.0, h / 2.0); // get coordinates for all corners to determine real image size Point2D[] ptSrc = new Point2D[4]; ptSrc[0] = new Point(0, 0); ptSrc[1] = new Point(w, 0); ptSrc[2] = new Point(w, h); ptSrc[3] = new Point(0, h); Point2D[] ptTgt = new Point2D[4]; tf.transform(ptSrc, 0, ptTgt, 0, ptSrc.length); Rectangle rc = new Rectangle(0, 0, w, h); for (Point2D p : ptTgt) { if (p.getX() < rc.x) { rc.width += rc.x - p.getX(); rc.x = (int) p.getX(); } if (p.getY() < rc.y) { rc.height += rc.y - p.getY(); rc.y = (int) p.getY(); } if (p.getX() > rc.x + rc.width) rc.width = (int) (p.getX() - rc.x); if (p.getY() > rc.y + rc.height) rc.height = (int) (p.getY() - rc.y); } BufferedImage imgTgt = new BufferedImage(rc.width, rc.height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = imgTgt.createGraphics(); // create a NEW rotation transformation around new center tf = AffineTransform.getRotateInstance(angle, rc.getWidth() / 2, rc.getHeight() / 2); g2d.setTransform(tf); g2d.drawImage(img, -rc.x, -rc.y, null); g2d.dispose(); drawOffset.x += rc.x; drawOffset.y += rc.y; return imgTgt; }
From source file:Main.java
private static ByteBuffer convertImageData(BufferedImage bufferedImage) { ByteBuffer imageBuffer;/* w w w . ja v a 2s. c o m*/ WritableRaster raster; BufferedImage texImage; // for a texture if (bufferedImage.getColorModel().hasAlpha()) { raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, bufferedImage.getWidth(), bufferedImage.getHeight(), 4, null); texImage = new BufferedImage(glAlphaColorModel, raster, false, new Hashtable<Object, Object>()); } else { raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, bufferedImage.getWidth(), bufferedImage.getHeight(), 3, null); texImage = new BufferedImage(glColorModel, raster, false, new Hashtable<Object, Object>()); } // copy the source image into the produced image Graphics g = texImage.getGraphics(); g.setColor(new Color(0f, 0f, 0f, 0f)); g.fillRect(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight()); g.drawImage(bufferedImage, 0, 0, null); // build a byte buffer from the temporary image // that be used by OpenGL to produce a texture. byte[] data = ((DataBufferByte) bufferedImage.getRaster().getDataBuffer()).getData(); imageBuffer = ByteBuffer.allocateDirect(data.length); imageBuffer.order(ByteOrder.nativeOrder()); imageBuffer.put(data, 0, data.length); imageBuffer.flip(); return imageBuffer; }