List of usage examples for java.awt.image BufferedImage getHeight
public int getHeight()
From source file:de.mprengemann.intellij.plugin.androidicons.util.ImageUtils.java
private static void verifyBorderImage(BufferedImage border) throws IOException { int[] rgb = border.getRGB(0, 0, border.getWidth(), border.getHeight(), null, 0, border.getWidth()); for (int aRgb : rgb) { if ((0xff000000 & aRgb) != 0) { if (aRgb != 0xff000000 && aRgb != 0xffff0000) { throw new IOException(); }/* w w w .ja v a 2 s . c o m*/ } } }
From source file:net.cloudkit.relaxation.CaptchaTest.java
public static List<BufferedImage> splitImage(BufferedImage img) throws Exception { final List<BufferedImage> subImgs = new ArrayList<BufferedImage>(); final int width = img.getWidth(); final int height = img.getHeight(); final List<Integer> weightList = new ArrayList<Integer>(); for (int x = 0; x < width; ++x) { int count = 0; for (int y = 0; y < height; ++y) { if (isWhite(img.getRGB(x, y), whiteThreshold) == 0) { count++;/*from ww w . j a v a 2 s. c om*/ } } weightList.add(count); } // System.out.println(weightList.size()); for (int i = 0; i < weightList.size(); i++) { int length = 0; while (i < weightList.size() && weightList.get(i) > 0) { i++; length++; } if (length > 18) { subImgs.add(removeBlank(img.getSubimage(i - length, 0, length / 2, height), whiteThreshold, 0)); subImgs.add(removeBlank(img.getSubimage(i - length / 2, 0, length / 2, height), whiteThreshold, 0)); } else if (length > 2) { subImgs.add(removeBlank(img.getSubimage(i - length, 0, length, height), whiteThreshold, 0)); } } return subImgs; }
From source file:net.cloudkit.relaxation.CaptchaTest.java
public static void clearNoise(BufferedImage image) { final int width = image.getWidth(); final int height = image.getHeight(); /*/* ww w . ja v a 2 s . c om*/ for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { image.setRGB(x, y, Color.WHITE.getRGB()); } } */ for (int x = image.getMinX(); x < width; x++) { for (int y = image.getMinY(); y < height; y++) { int point = image.getRGB(x, y); // int top = (y > 0) ? image.getRGB(x, y - 1) : -1; // ? int right = (x < width - 1) ? image.getRGB(x + 1, y) : -1; // int bottom = (y < height - 1) ? image.getRGB(x, y + 1) : -1; // int left = (x > 0) ? image.getRGB(x - 1, y) : -1; // ? int topRight = ((x < width - 1) && (y > 0)) ? image.getRGB(x + 1, y - 1) : -1; // int topLeft = ((x > 0) && (y > 0)) ? image.getRGB(x - 1, y - 1) : -1; // ? int bottomRight = ((x < width - 1) && (y < height - 1)) ? image.getRGB(x + 1, y + 1) : -1; // int bottomLeft = ((x > 0) && (y < height - 1)) ? image.getRGB(x - 1, y + 1) : -1; int i = 0; i = (top != -1) ? i + 1 : i; i = (right != -1) ? i + 1 : i; i = (bottom != -1) ? i + 1 : i; i = (left != -1) ? i + 1 : i; i = (topRight != -1) ? i + 1 : i; i = (topLeft != -1) ? i + 1 : i; i = (bottomRight != -1) ? i + 1 : i; i = (bottomLeft != -1) ? i + 1 : i; // System.out.println("i:" + i + ", top:" + top + ", right:" + right + ", bottom:" + bottom + ", left:" + left + ", topRight:" + topRight + ", topLeft:" + topLeft + ", bottomRight:" + bottomRight + ", bottomLeft:" + bottomLeft); if (i < 5) { image.setRGB(x, y, Color.WHITE.getRGB()); } /* int leftNearby = 0; if(left != -1) { int secondLeft = (x > 1) ? image.getRGB(x - 2, y) : -1; int threeLeft = (x > 2) ? image.getRGB(x - 3, y) : -1; leftNearby = ((left == -1) ? 0 : 1) + ((secondLeft == -1) ? 0 : 1) + ((threeLeft == -1) ? 0 : 1); } int rightNearby = 0; if(right != -1) { int secondRight = (x + 1 < width - 1) ? image.getRGB(x + 2, y) : -1; int threeRight = (x + 2 < width - 1) ? image.getRGB(x + 3, y) : -1; rightNearby = ((right == -1) ? 0 : 1) + ((secondRight == -1) ? 0 : 1) + ((threeRight == -1) ? 0 : 1); } int topNearby = 0; if(top != -1) { int secondTop = (y > 1) ? image.getRGB(x, y - 2) : -1; int threeTop = (y > 2) ? image.getRGB(x, y - 3) : -1; topNearby = ((top == -1) ? 0 : 1) + ((secondTop == -1) ? 0 : 1) + ((threeTop == -1) ? 0 : 1); } int bottomNearby = 0; if(bottom != -1) { int secondBottom = (y + 1 < height - 1) ? image.getRGB(x, y + 2) : -1; int threeBottom = (y + 2 < height - 1) ? image.getRGB(x, y + 3) : -1; bottomNearby = ((bottom == -1) ? 0 : 1) + ((secondBottom == -1) ? 0 : 1) + ((threeBottom == -1) ? 0 : 0); } System.out.println(leftNearby + " " + rightNearby + " " + topNearby + " " + bottomNearby); if (leftNearby != 2 && rightNearby != 2 && topNearby != 2 && bottomNearby != 2) { image.setRGB(x, y, Color.WHITE.getRGB()); } */ /* System.out.println(point - top); System.out.println(point - right); System.out.println(point - bottom); System.out.println(point - left); System.out.println(point - topRight); System.out.println(point - topLeft); System.out.println(point - bottomRight); System.out.println(point - bottomLeft); */ // if (point != top && point != right && point != bottom && point != left && point != topRight && point != topLeft && point != bottomRight && point != bottomLeft) { // image.setRGB(x, y, Color.WHITE.getRGB()); // } /* Color color = new Color(image.getRGB(x, y)); if((color.getBlue() < 120) || ((color.getRed() + color.getGreen() + color.getBlue()) < 50)) { // image.setRGB(x, y, Color.WHITE.getRGB()); } else if((color.getRed() + color.getGreen() + color.getBlue()) < 400) { image.setRGB(x, y, Color.BLACK.getRGB()); } */ Color color = new Color(image.getRGB(x, y)); if ((color.getRed() + color.getGreen() + color.getBlue()) < 600) { image.setRGB(x, y, Color.BLACK.getRGB()); } else { image.setRGB(x, y, Color.WHITE.getRGB()); } } } }
From source file:Main.java
private static IntBuffer getImageAsARGBIntBuffer(BufferedImage image) { DataBuffer buffer = image.getRaster().getDataBuffer(); if (buffer instanceof DataBufferInt) { return IntBuffer.wrap(((DataBufferInt) buffer).getData()); } else if (buffer instanceof DataBufferByte) { return ByteBuffer.wrap(((DataBufferByte) buffer).getData()).order(ByteOrder.BIG_ENDIAN).asIntBuffer(); } else {//from ww w . j av a 2s . com int width = image.getWidth(); int height = image.getHeight(); int[] pixels = new int[width * height]; image.getRGB(0, 0, width, height, pixels, 0, width); return IntBuffer.wrap(pixels); } }
From source file:com.silverpeas.util.ImageUtil.java
public static String[] getWidthAndHeightByHeight(InputStream image, int heightParam) { String[] result = new String[2]; try {/*from w w w.j ava2 s . c o m*/ BufferedImage inputBuf = ImageIO.read(image); // calcul de la taille de la sortie double inputBufWidth; double inputBufHeight; double height; double ratio; double width; if (inputBuf.getHeight() > heightParam) { inputBufHeight = inputBuf.getHeight(); inputBufWidth = inputBuf.getWidth(); height = heightParam; ratio = inputBufHeight / height; width = inputBufWidth / ratio; } else { height = inputBuf.getHeight(); width = inputBuf.getWidth(); } String sWidth = Double.toString(width); String sHeight = Double.toString(height); result[0] = sWidth.substring(0, sWidth.indexOf('.')); result[1] = sHeight.substring(0, sHeight.indexOf('.')); return result; } catch (Exception e) { SilverTrace.error("util", "ImageUtil.getWidthAndHeightByHeight", "root.MSG_GEN_ERROR", e); } return result; }
From source file:ImageProcessing.ImageProcessing.java
public static double[] extractGrayColor(BufferedImage source) { //Extracts the gray value from the pixels at the source by //calculating the average of the RGB value at the given pixel. int imageWidth = source.getWidth(); int imageHeight = source.getHeight(); double[] values = new double[imageWidth * imageHeight]; for (int i = 0; i < imageHeight; i++) { for (int j = 0; j < imageWidth; j++) { int rgbValue = source.getRGB(j, i); Color currentPixel = new Color(rgbValue, true); int value = (currentPixel.getRed() + currentPixel.getGreen() + currentPixel.getBlue()) / 3; values[(i * imageWidth) + j] = value; }// w w w . ja v a 2 s . com } return values; }
From source file:ar.com.zauber.common.image.impl.AbstractImage.java
/** * Creates a thumbnail/* w w w . j a v a2 s .c o m*/ * * @param is data source * @param os data source * @throws IOException if there is a problem reading is */ public static void createThumbnail(final InputStream is, final OutputStream os, final int target) throws IOException { final float compression = 0.85F; ImageWriter writer = null; MemoryCacheImageOutputStream mos = null; Graphics2D graphics2D = null; try { final BufferedImage bi = ImageIO.read(is); final Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("JPG"); if (!iter.hasNext()) { throw new IllegalStateException("can't find JPG subsystem"); } int w = bi.getWidth(), h = bi.getHeight(); if (w < target && h < target) { // nothing to recalculate, ya es chiquita. } else { if (w > h) { h = target * bi.getHeight() / bi.getWidth(); w = target; } else { w = target * bi.getWidth() / bi.getHeight(); h = target; } } // draw original image to thumbnail image object and // scale it to the new size on-the-fly final BufferedImage thumbImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); graphics2D = thumbImage.createGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics2D.drawImage(bi, 0, 0, w, h, null); writer = (ImageWriter) iter.next(); final ImageWriteParam iwp = writer.getDefaultWriteParam(); iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); iwp.setCompressionQuality(compression); mos = new MemoryCacheImageOutputStream(os); writer.setOutput(mos); writer.write(null, new IIOImage(thumbImage, null, null), iwp); } finally { if (writer != null) { writer.dispose(); } if (mos != null) { mos.close(); } if (graphics2D != null) { graphics2D.dispose(); } is.close(); os.close(); } }
From source file:edu.nps.moves.mmowgli.modules.userprofile.InstallImageDialog.java
public static MediaImage putFileImageIntoDbTL(File f, String name, String mimeType) throws IOException { Image imgObj = new Image(name, mimeType); FileInputStream fis = new FileInputStream(f); byte[] ba = IOUtils.toByteArray(fis); imgObj.setBytes(ba);//from w ww .j a va2 s. com InputStream bain = new ByteArrayInputStream(ba); BufferedImage bimg = ImageIO.read(bain); imgObj.setWidth(bimg.getWidth()); imgObj.setHeight(bimg.getHeight()); Image.saveTL(imgObj); Media med = new Media(); med.setDescription(imgObj.getName() + " in db"); med.setSource(Media.Source.DATABASE); med.setType(MediaType.IMAGE); med.setHandle("" + bimg.getWidth() + "x" + bimg.getHeight()); med.setUrl(imgObj.getName()); med.setWidth((long) bimg.getWidth()); med.setHeight((long) bimg.getHeight()); Media.saveTL(med); return new MediaImage(med, imgObj); }
From source file:de.mprengemann.intellij.plugin.androidicons.images.ImageUtils.java
private static BufferedImage trim9PBorder(BufferedImage inputImage) { BufferedImage trimedImage = UIUtil.createImage(inputImage.getWidth() - 2, inputImage.getHeight() - 2, BufferedImage.TYPE_INT_ARGB); Graphics2D g = trimedImage.createGraphics(); g.drawImage(inputImage, 0, 0, trimedImage.getWidth(), trimedImage.getHeight(), 1, 1, inputImage.getWidth() - 1, inputImage.getHeight() - 1, null); g.dispose();/*from w ww. j a va 2 s . co m*/ return trimedImage; }
From source file:de.darkblue.bongloader2.utils.ToolBox.java
public static BufferedImage grayScale(BufferedImage image) { BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY); Graphics g = newImage.getGraphics(); g.drawImage(image, 0, 0, null);/*from ww w .ja v a 2 s .c om*/ g.dispose(); return newImage; }