List of usage examples for java.awt.image BufferedImage getWidth
public int getWidth()
From source file:com.jaeksoft.searchlib.util.ImageUtils.java
public final static BufferedImage reduceImage(BufferedImage image, int percent) { if (percent >= 100) return image; float fPercent = (float) percent / 100; float newWidth = (float) (image.getWidth()) * fPercent; float newHeight = (float) (image.getHeight()) * fPercent; return reduceImage(image, (int) newWidth, (int) newHeight); }
From source file:common.utils.ImageUtils.java
/** * ? ?//from ww w.j a v a 2 s . co m * @param scaling scaling * @param image picture * @return ? */ public static Dimension getDimmension(double scaling, BufferedImage image) { return new Dimension((int) (scaling * image.getWidth()), (int) (scaling * image.getHeight())); }
From source file:ml.hsv.java
public static hsv[][] img2RGB2HSV(String ip) throws IOException { BufferedImage image; int width, height; File input = new File(ip); image = ImageIO.read(input);// ww w.j a v a 2s. c o m width = image.getWidth(); height = image.getHeight(); hsv hsvImage[][] = new hsv[height][width]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Color c = new Color(image.getRGB(j, i)); hsvImage[i][j] = new hsv(c.getRed(), c.getGreen(), c.getBlue()); } } HSV2File(hsvImage, width, height); return hsvImage; }
From source file:ch.rasc.downloadchart.DownloadChartServlet.java
private static Dimension calculateDimension(BufferedImage image, Integer width, Integer height) { int imgWidth = image.getWidth(); int imgHeight = image.getHeight(); if (width == null && height != null) { return new Dimension(imgWidth * height / imgHeight, height); } else if (width != null && height == null) { return new Dimension(width, imgHeight * width / imgWidth); } else if (width != null && height != null) { return new Dimension(width, height); }// w w w. java 2 s. c o m return null; }
From source file:com.mycollab.mobile.ui.MobileAttachmentUtils.java
public static void saveContentsToRepo(String attachmentPath, Map<String, File> fileStores) { if (MapUtils.isNotEmpty(fileStores)) { ResourceService resourceService = AppContextUtil.getSpringBean(ResourceService.class); for (Map.Entry<String, File> entry : fileStores.entrySet()) { try { String fileExt = ""; String fileName = entry.getKey(); File file = entry.getValue(); int index = fileName.lastIndexOf("."); if (index > 0) { fileExt = fileName.substring(index + 1, fileName.length()); }/* w w w. j a va2 s . co m*/ if ("jpg".equalsIgnoreCase(fileExt) || "png".equalsIgnoreCase(fileExt)) { try { BufferedImage bufferedImage = ImageIO.read(file); int imgHeight = bufferedImage.getHeight(); int imgWidth = bufferedImage.getWidth(); BufferedImage scaledImage; float scale; float destWidth = 974; float destHeight = 718; float scaleX = Math.min(destHeight / imgHeight, 1); float scaleY = Math.min(destWidth / imgWidth, 1); scale = Math.min(scaleX, scaleY); scaledImage = ImageUtil.scaleImage(bufferedImage, scale); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); ImageIO.write(scaledImage, fileExt, outStream); resourceService.saveContent(constructContent(fileName, attachmentPath), UserUIContext.getUsername(), new ByteArrayInputStream(outStream.toByteArray()), MyCollabUI.getAccountId()); } catch (IOException e) { LOG.error("Error in upload file", e); resourceService.saveContent(constructContent(fileName, attachmentPath), UserUIContext.getUsername(), new FileInputStream(fileStores.get(fileName)), MyCollabUI.getAccountId()); } } else { resourceService.saveContent(constructContent(fileName, attachmentPath), UserUIContext.getUsername(), new FileInputStream(file), MyCollabUI.getAccountId()); } } catch (FileNotFoundException e) { LOG.error("Error when attach content in UI", e); } } } }
From source file:de.ppi.selenium.util.ScreenshotUtils.java
/** * Calculate how similar the 2 immages are. * * @param var picture1/*from ww w .j a va 2 s. c o m*/ * @param cont picture2 * @return a value between 0 and 1. */ private static double similarity(BufferedImage var, BufferedImage cont) { final int scale = 3; double[] varArr = new double[var.getWidth() * var.getHeight() * scale]; double[] contArr = new double[cont.getWidth() * cont.getHeight() * scale]; if (varArr.length != contArr.length) { throw new IllegalStateException("The pictures are different sizes!"); } // unroll pixels for (int i = 0; i < var.getHeight(); i++) { for (int j = 0; j < var.getWidth(); j++) { varArr[i * var.getWidth() + j + 0] = new Color(var.getRGB(j, i)).getRed(); contArr[i * cont.getWidth() + j + 0] = new Color(cont.getRGB(j, i)).getRed(); varArr[i * var.getWidth() + j + 1] = new Color(var.getRGB(j, i)).getGreen(); contArr[i * cont.getWidth() + j + 1] = new Color(cont.getRGB(j, i)).getGreen(); varArr[i * var.getWidth() + j + 2] = new Color(var.getRGB(j, i)).getBlue(); contArr[i * cont.getWidth() + j + 2] = new Color(cont.getRGB(j, i)).getBlue(); } } double mins = 0; double maxs = 0; for (int i = 0; i != varArr.length; i++) { if (varArr[i] > contArr[i]) { mins += contArr[i]; maxs += varArr[i]; } else { mins += varArr[i]; maxs += contArr[i]; } } return mins / maxs; }
From source file:ml.hsv.java
public static hsv[][] img2RGB2HSV(File input) throws IOException { BufferedImage image; int width, height; // File input = new File(ip); image = ImageIO.read(input);/*from w w w . ja v a 2 s .c o m*/ width = image.getWidth(); height = image.getHeight(); hsv hsvImage[][] = new hsv[height][width]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Color c = new Color(image.getRGB(j, i)); hsvImage[i][j] = new hsv(c.getRed(), c.getGreen(), c.getBlue()); } } // HSV2File(hsvImage,width,height); debugging code removed return hsvImage; }
From source file:ImageProcessing.ImageProcessing.java
public static void processGrayscale(BufferedImage image) { //Converts a color image to a Grayscale image. for (int i = 0; i < image.getHeight(); i++) { for (int j = 0; j < image.getWidth(); j++) { int rgb = image.getRGB(j, i); Color currentPixel = new Color(rgb, true); //Find the average from all the color components for the given pixel. int grayLevel = (currentPixel.getRed() + currentPixel.getGreen() + currentPixel.getBlue()) / 3; int gray = (grayLevel << 16) + (grayLevel << 8) + grayLevel; image.setRGB(j, i, gray);//from ww w. ja v a 2 s. com } } }
From source file:com.alvermont.terraj.stargen.ui.UIUtils.java
/** * Scale an image to a particular X and Y size in pixels * /*from w w w. java 2 s .c om*/ * @param image The image to be scaled * @param pixelsX The desired horizontal size in pixels * @param pixelsY The desired vertical size in pixels * @return A new image scaled to the requested dimensions */ public static BufferedImage scaleImage(BufferedImage image, int pixelsX, int pixelsY) { int actualWidth = image.getWidth(); int actualHeight = image.getHeight(); // work out the scale factor double sx = (float) (pixelsX) / actualWidth; double sy = (float) (pixelsY) / actualHeight; BufferedImage nbi = new BufferedImage(pixelsX, pixelsY, image.getType()); Graphics2D g2 = nbi.createGraphics(); AffineTransform at = AffineTransform.getScaleInstance(sx, sy); g2.setTransform(at); g2.drawImage(image, 0, 0, null); return nbi; }
From source file:com.vaadin.testbench.screenshot.ImageUtil.java
/** * Clones the given BufferedImage//w w w . j av a2s . com * * @param sourceImage * The image to copy * @return A copy of sourceImage */ public static BufferedImage cloneImage(BufferedImage sourceImage) { // This method could likely be optimized but the gain is probably // small final int w = sourceImage.getWidth(); final int h = sourceImage.getHeight(); BufferedImage newImage = new BufferedImage(w, h, TYPE_INT_RGB); Graphics2D g = (Graphics2D) newImage.getGraphics(); g.drawImage(sourceImage, 0, 0, w, h, null); g.dispose(); return newImage; }