List of usage examples for java.awt.image BufferedImage getRGB
public int getRGB(int x, int y)
From source file:Main.java
protected static boolean testNeighbour(BufferedImage source, int x, int y, boolean alpha) { if (x >= 0 && y >= 0 && x < source.getWidth() && y < source.getHeight()) { int gray = source.getRGB(x, y) & 0x000000ff; int alphaI = (source.getRGB(x, y) & 0xff000000) >>> 24; return (alpha && alphaI == 0) || (!alpha && gray == 255); }// w w w .ja va 2s. c om return true; }
From source file:Main.java
/** * This method cleans input image by replacing all pixels with RGB values * from -3092272 (light gray) to -1 (white) with white pixels and * from -3092272 (light gray) to -16777216 (black) with black pixels * @param image - input image that will be cleaned * @return - cleaned input image as BufferedImage *///from www . ja v a 2s .com public static BufferedImage blackAndLightGrayCleaning(BufferedImage image) { for (int j = 0; j < image.getHeight(); j++) { for (int i = 0; i < image.getWidth(); i++) { if (image.getRGB(i, j) > -3092272) { image.setRGB(i, j, -1); } else { image.setRGB(i, j, -16777216); } } } return image; }
From source file:Main.java
/** * This method cleans input image by replacing all pixels with RGB values * from RGBcolor input (the input color) to -1 (white) with white pixels and * from RGBcolor input (the input color) to -16777216 (black) with black pixels * @param image - input image that will be cleaned * @param RGBcolor - input RGB value of wanted color as reference for celaning * @return - cleaned input image as BufferedImage *//*from w w w . j a va 2s. com*/ public static BufferedImage colorCleaning(BufferedImage image, int RGBcolor) { for (int j = 0; j < image.getHeight(); j++) { for (int i = 0; i < image.getWidth(); i++) { if (image.getRGB(i, j) == RGBcolor) { image.setRGB(i, j, -16777216); } else { image.setRGB(i, j, -1); } } } return image; }
From source file:org.orphanware.App.java
private static boolean getPixel(BufferedImage img, int x, int y) { int rgb = img.getRGB(x, y); // From http://stackoverflow.com/questions/4801366/convert-rgb-values-into-integer-pixel int r = (rgb >> 16) & 0x0ff; int g = (rgb >> 8) & 0x0ff; int b = (rgb) & 0x0ff; int grayscale = (r + g + b) / 3; return grayscale >= 127; }
From source file:Main.java
public static BufferedImage replaceColor(BufferedImage src, int sourceRGB, int replaceRGB) { for (int y = 0; y < src.getHeight(); y++) { for (int x = 0; x < src.getWidth(); x++) { int rawRGB = src.getRGB(x, y); int rgb = rawRGB & 0xffffff; int alpha = rawRGB & 0xff000000; if (rgb == sourceRGB) { src.setRGB(x, y, alpha | replaceRGB); }//from w ww .j av a2 s . c o m } } return src; }
From source file:Main.java
/** * This method reads the input image from the input from * start pixel height (y1) until it reads the first next row * where all pixel are white by height and return that value * @param Img - input image that will be read * @param y1 - input start height pixel of image * @return - returns the value of height when conditions are true *///ww w. j a v a 2s . co m private static int trimLockdown(BufferedImage Img, int y1) { for (int j = y1 + 1; j < Img.getHeight(); j++) { int counterWhite = 0; for (int i = 0; i < Img.getWidth(); i++) { if (Img.getRGB(i, j) == -1) { counterWhite++; } } if (counterWhite == Img.getWidth()) { //this is a chek for dots over the letters i and j //so they wont be missread as dots if (j > (Img.getHeight() / 2)) { return j; } } if (j == Img.getHeight() - 1) { return j + 1; } } return 0; }
From source file:Main.java
public static int[] columnChecksums(BufferedImage img) { int[] sums = new int[img.getWidth()]; Arrays.fill(sums, 0);//w w w . ja v a 2 s.co m for (int y = 0; y < img.getHeight(); y++) { for (int x = 0; x < img.getWidth(); x++) { final int colour = img.getRGB(x, y); sums[x] += (int) ((colour & 0x00ff0000) >> 16); sums[x] += (int) ((colour & 0x0000ff00) >> 8); sums[x] += (int) (colour & 0x000000ff); } } for (int x = 0; x < img.getWidth(); x++) { sums[x] %= 256; } return sums; }
From source file:org.apache.axis2.jaxws.utility.AttachmentUtils.java
public static boolean compareImages(Image img1, Image img2) { if (img1 == null && img2 == null) { if (log.isDebugEnabled()) { log.debug("Both Image Objects are null, cannot compare Images returning false"); }// w ww . java2s. co m return false; } int h1 = img1.getHeight(null); int h2 = img2.getHeight(null); int w1 = img1.getWidth(null); int w2 = img1.getWidth(null); if (h1 != h2 || w1 != w2) { return false; } if (img1 instanceof BufferedImage && img2 instanceof BufferedImage) { BufferedImage bi1 = (BufferedImage) img1; BufferedImage bi2 = (BufferedImage) img2; for (int h = 0; h < h1; ++h) { for (int w = 0; w < w1; ++w) { int Img1Pixel = bi1.getRGB(w, h); int Img2Pixel = bi2.getRGB(w, h); if (Img1Pixel != Img2Pixel) { return false; } } } } return true; }
From source file:Main.java
public static BufferedImage getTransparentImage(BufferedImage image, Color transparent) { BufferedImage img = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = img.createGraphics(); for (int x = 0; x < img.getWidth(); x++) { for (int y = 0; y < img.getHeight(); y++) { if (image.getRGB(x, y) != transparent.getRGB()) { img.setRGB(x, y, image.getRGB(x, y)); }// www . j a v a 2 s . co m } } g.dispose(); return img; }
From source file:Main.java
static BufferedImage enlarge(BufferedImage image, int n) { int w = image.getWidth() / n; int h = image.getHeight() / n; BufferedImage shrunkImage = new BufferedImage(w, h, image.getType()); for (int y = 0; y < h; ++y) for (int x = 0; x < w; ++x) shrunkImage.setRGB(x, y, image.getRGB(x * n, y * n)); return shrunkImage; }