List of utility methods to do BufferedImage Operation
BufferedImage | fixImage(BufferedImage img, String ext) Fixes image type based on the file extension. if ("jpg".equalsIgnoreCase(ext)) { int w = img.getWidth(); int h = img.getHeight(); BufferedImage newImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); int[] rgb = img.getRGB(0, 0, w, h, null, 0, w); newImage.setRGB(0, 0, w, h, rgb, 0, w); img = newImage; return img; |
BufferedImage | floatBufferToGrayBufferedImage(FloatBuffer floatBuffer, BufferedImage bi) Converts float values to an unsigned short BufferedImage .
if (bi.getType() != BufferedImage.TYPE_USHORT_GRAY) throw new IllegalArgumentException( "Invalid image type. Expect image " + "type BufferedImage.TYPE_USHORT_GRAY."); int maxDepth = 1 << 16 - 1; float min = Float.MAX_VALUE; float max = Float.MIN_VALUE; floatBuffer.rewind(); while (floatBuffer.remaining() > 0) { ... |
boolean | floodFill(BufferedImage img, int startX, int startY, Color targetColor, Color replacementColor) Performs flood fill on the image. return floodFill(img, startX, startY, targetColor.getRGB(), replacementColor.getRGB());
|
Point[] | fuzzyCompare(final BufferedImage img1, final BufferedImage img2, final double colorTolerance, final double pixelTolerance, final int fuzzyBlockDimension) Compares two images by partitioning them into blocks and checking the number of different pixels in each block. final ArrayList<Point> pixels = new ArrayList<>(); final int horizontalBlockCount = img1.getWidth() / fuzzyBlockDimension; final int verticalBlockCount = img1.getHeight() / fuzzyBlockDimension; for (int x = 0; x < horizontalBlockCount; x++) { for (int y = 0; y < verticalBlockCount; y++) { final ArrayList<Point> tempCoordinates = new ArrayList<>(); final int horizontalBlockWidth = calcBlockLength(fuzzyBlockDimension, x, img1.getWidth()); final int verticalBlockHeight = calcBlockLength(fuzzyBlockDimension, y, img1.getHeight()); ... |
boolean | fuzzyEquals(BufferedImage a, BufferedImage b, int threshold) fuzzy Equals int aw = a.getWidth(); int ah = a.getHeight(); int bw = b.getWidth(); int bh = b.getHeight(); if ((aw != bw) || (ah != bh)) return false; for (int y = 0; y < ah; y++) for (int x = 0; x < bw; x++) { ... |
BufferedImage | genBlackAndWhiteImage(BufferedImage image) Generate Black and white image. BufferedImage blackAndWhiteImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_BYTE_BINARY); Graphics2D g = (Graphics2D) blackAndWhiteImage.getGraphics(); g.drawImage(image, 0, 0, null); g.dispose(); image = blackAndWhiteImage; return image; |
Color[][] | generate(int w, int h, BufferedImage img) generate Color[][] ret = new Color[h][w]; int reqW = 5 * w; int reqH = 5 * h; float ratio = Math.max((reqW + 0.0f) / img.getWidth(), (reqH + 0.0f) / img.getHeight()); img = resizeImage(img, (int) (img.getWidth() * ratio), (int) (img.getHeight() * ratio)); int xFill = (int) Math.max(0, (img.getWidth() - reqW) / 2.0f); int yFill = (int) Math.max(0, (img.getHeight() - reqH) / 2.0f); for (int y = 0; y < h; y++) { ... |
BufferedImage | generateBufferedImageFromComponent(Component component) Erstellt Image aus einer (Java)Komponente BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); g.setColor(component.getBackground()); g.fillRect(0, 0, image.getWidth(), image.getHeight()); component.print(g); g.dispose(); return image; ... |
String | generateImageHash(BufferedImage image) Generates blocks representing an image by dividing the image up in 16x16 pixel blocks and calculating a mean value of the color in each block. int width = image.getWidth(); int height = image.getHeight(); byte[] data = new byte[width * height * 3]; int idx = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int rgb = image.getRGB(x, y); rgb &= 0x00FCFCFC; ... |
BufferedImage | generateOutline(BufferedImage source, Color color, boolean alpha) generate Outline return generateOutline(source, color, color, alpha);
|