List of usage examples for java.awt.image BufferedImage setRGB
public void setRGB(int x, int y, int rgb)
From source file:org.iish.visualmets.services.ImageTransformation.java
/** * Returns a 90 degrees rotated image//from ww w. jav a2s . c o m * * @param bi image * @return a rotated image */ private BufferedImage RotateImage90Degrees(BufferedImage bi) { int width = bi.getWidth(); int height = bi.getHeight(); BufferedImage biFlip = new BufferedImage(height, width, bi.getType()); for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) { biFlip.setRGB(height - 1 - j, i, bi.getRGB(i, j)); } return biFlip; }
From source file:org.iish.visualmets.services.ImageTransformation.java
/** * Returns a 180 degrees rotated image// w w w. j ava 2s.c o m * * @param bi image * @return a rotated image */ private BufferedImage RotateImage180Degrees(BufferedImage bi) { int width = bi.getWidth(); int height = bi.getHeight(); BufferedImage biFlip = new BufferedImage(width, height, bi.getType()); for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) { biFlip.setRGB(width - 1 - i, height - 1 - j, bi.getRGB(i, j)); } return biFlip; }
From source file:org.iish.visualmets.services.ImageTransformation.java
/** * Returns a 270 degrees rotated image//from w w w. j a v a2s . c om * * @param bi image * @return a rotated image */ private BufferedImage RotateImage270Degrees(BufferedImage bi) { int width = bi.getWidth(); int height = bi.getHeight(); BufferedImage biFlip = new BufferedImage(height, width, bi.getType()); for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) { biFlip.setRGB(j, width - 1 - i, bi.getRGB(i, j)); } return biFlip; }
From source file:com.xuggle.xuggler.UtilsTest.java
@SuppressWarnings("deprecation") @Test//from ww w. j a v a2 s .co m public void testImageToImageSolidColor() { int w = 50; int h = 50; int gray = Color.GRAY.getRGB(); // construct an all gray image BufferedImage image1 = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR); for (int x = 0; x < w; ++x) for (int y = 0; y < h; ++y) image1.setRGB(x, y, gray); // convert image1 to a picture and then back to image2 BufferedImage image2 = Utils.videoPictureToImage(Utils.imageToVideoPicture(image1, 0)); // test that all the pixels in image2 are gray, but not black or // white for (int x = 0; x < w; ++x) for (int y = 0; y < h; ++y) { int pixel = image2.getRGB(x, y); assertTrue("color value missmatch", pixel == gray); } }
From source file:org.sejda.sambox.pdmodel.graphics.image.JPEGFactoryTest.java
@Test public void testCreateFromImageINT_ARGB() throws IOException { // workaround Open JDK bug // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7044758 if (System.getProperty("java.runtime.name").equals("OpenJDK Runtime Environment") && (System.getProperty("java.specification.version").equals("1.6") || System.getProperty("java.specification.version").equals("1.7") || System.getProperty("java.specification.version").equals("1.8"))) { return;/* www. j a v a2s .c o m*/ } PDDocument document = new PDDocument(); BufferedImage image = ImageIO.read(JPEGFactoryTest.class.getResourceAsStream("jpeg.jpg")); // create an ARGB image int width = image.getWidth(); int height = image.getHeight(); BufferedImage argbImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics ag = argbImage.getGraphics(); ag.drawImage(image, 0, 0, null); ag.dispose(); for (int x = 0; x < argbImage.getWidth(); ++x) { for (int y = 0; y < argbImage.getHeight(); ++y) { argbImage.setRGB(x, y, (argbImage.getRGB(x, y) & 0xFFFFFF) | ((y / 10 * 10) << 24)); } } PDImageXObject ximage = JPEGFactory.createFromImage(argbImage); validate(ximage, 8, width, height, "jpg", PDDeviceRGB.INSTANCE.getName()); assertNotNull(ximage.getSoftMask()); validate(ximage.getSoftMask(), 8, width, height, "jpg", PDDeviceGray.INSTANCE.getName()); assertTrue(colorCount(ximage.getSoftMask().getImage()) > image.getHeight() / 10); doWritePDF(document, ximage, testResultsDir, "jpeg-intargb.pdf"); }
From source file:org.sejda.sambox.pdmodel.graphics.image.JPEGFactoryTest.java
@Test public void testCreateFromImage4BYTE_ABGR() throws IOException { // workaround Open JDK bug // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7044758 if (System.getProperty("java.runtime.name").equals("OpenJDK Runtime Environment") && (System.getProperty("java.specification.version").equals("1.6") || System.getProperty("java.specification.version").equals("1.7") || System.getProperty("java.specification.version").equals("1.8"))) { return;//from w ww .j av a 2 s . co m } PDDocument document = new PDDocument(); BufferedImage image = ImageIO.read(JPEGFactoryTest.class.getResourceAsStream("jpeg.jpg")); // create an ARGB image int width = image.getWidth(); int height = image.getHeight(); BufferedImage argbImage = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR); Graphics ag = argbImage.getGraphics(); ag.drawImage(image, 0, 0, null); ag.dispose(); for (int x = 0; x < argbImage.getWidth(); ++x) { for (int y = 0; y < argbImage.getHeight(); ++y) { argbImage.setRGB(x, y, (argbImage.getRGB(x, y) & 0xFFFFFF) | ((y / 10 * 10) << 24)); } } PDImageXObject ximage = JPEGFactory.createFromImage(argbImage); validate(ximage, 8, width, height, "jpg", PDDeviceRGB.INSTANCE.getName()); assertNotNull(ximage.getSoftMask()); validate(ximage.getSoftMask(), 8, width, height, "jpg", PDDeviceGray.INSTANCE.getName()); assertTrue(colorCount(ximage.getSoftMask().getImage()) > image.getHeight() / 10); doWritePDF(document, ximage, testResultsDir, "jpeg-4bargb.pdf"); }
From source file:fr.gael.drb.cortex.topic.sentinel3.jai.operator.QuicklookSlstrRIF.java
private BufferedImage toGrayScale(Raster in, PixelCorrection c, boolean invertColors, double lowerBound, double upperBound) { double offset = -lowerBound; double scaleFactor = 256. / (upperBound - lowerBound); int width = in.getWidth(); int height = in.getHeight(); // generate//from w w w .j a v a 2s.c om BufferedImage out = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { int pixel = checkAndApplyCorrection(in.getSample(i, j, 0), c); if (pixel == c.nodata) { if (invertColors) out.setRGB(i, j, new Color(255, 255, 255).getRGB()); else out.setRGB(i, j, new Color(0, 0, 0).getRGB()); continue; } double normalized = (pixel + offset) * scaleFactor; int gray = (int) (Math.max(0, Math.min(255, normalized))); if (invertColors) gray = 255 - gray; out.setRGB(i, j, new Color(gray, gray, gray).getRGB()); } } return out; }
From source file:preprocessing.Utils.java
public static BufferedImage removeNoisePoints(BufferedImage img) { for (int i = 0; i < img.getWidth(); i++) { for (int j = 0; j < img.getHeight(); j++) { int negros = 0; if (i + 1 < img.getWidth() && img.getRGB(i + 1, j) == -16777216) negros++;/*from ww w .j a v a 2 s. c om*/ if (i + 1 < img.getWidth() && j - 1 >= 0 && img.getRGB(i + 1, j - 1) == -16777216) negros++; if (j - 1 >= 0 && img.getRGB(i, j - 1) == -16777216) negros++; if (i - 1 >= 0 && j - 1 >= 0 && img.getRGB(i - 1, j - 1) == -16777216) negros++; if (i - 1 >= 0 && img.getRGB(i - 1, j) == -16777216) negros++; if (i - 1 >= 0 && j + 1 < img.getHeight() && img.getRGB(i - 1, j + 1) == -16777216) negros++; if (j + 1 < img.getHeight() && img.getRGB(i, j + 1) == -16777216) negros++; if (i + 1 < img.getWidth() && j + 1 < img.getHeight() && img.getRGB(i + 1, j + 1) == -16777216) negros++; if (negros <= 2) img.setRGB(i, j, -1); } } return img; }
From source file:net.sf.mzmine.modules.visualization.twod.TwoDXYPlot.java
public boolean render(final Graphics2D g2, final Rectangle2D dataArea, int index, PlotRenderingInfo info, CrosshairState crosshairState) { // if this is not TwoDDataSet if (index != 0) return super.render(g2, dataArea, index, info, crosshairState); // prepare some necessary constants final int x = (int) dataArea.getX(); final int y = (int) dataArea.getY(); final int width = (int) dataArea.getWidth(); final int height = (int) dataArea.getHeight(); final double imageRTMin = (double) getDomainAxis().getRange().getLowerBound(); final double imageRTMax = (double) getDomainAxis().getRange().getUpperBound(); final double imageRTStep = (imageRTMax - imageRTMin) / width; final double imageMZMin = (double) getRangeAxis().getRange().getLowerBound(); final double imageMZMax = (double) getRangeAxis().getRange().getUpperBound(); final double imageMZStep = (imageMZMax - imageMZMin) / height; if ((zoomOutBitmap != null) && (imageRTMin == totalRTRange.getMin()) && (imageRTMax == totalRTRange.getMax()) && (imageMZMin == totalMZRange.getMin()) && (imageMZMax == totalMZRange.getMax()) && (zoomOutBitmap.getWidth() == width) && (zoomOutBitmap.getHeight() == height)) { g2.drawImage(zoomOutBitmap, x, y, null); return true; }//from w ww .j a v a 2 s.co m // Save current time Date renderStartTime = new Date(); // prepare a double array of summed intensities double values[][] = new double[width][height]; maxValue = 0; // now this is an instance variable Random r = new Random(); for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) { double pointRTMin = imageRTMin + (i * imageRTStep); double pointRTMax = pointRTMin + imageRTStep; double pointMZMin = imageMZMin + (j * imageMZStep); double pointMZMax = pointMZMin + imageMZStep; double lv = dataset.getMaxIntensity(new Range(pointRTMin, pointRTMax), new Range(pointMZMin, pointMZMax), plotMode); if (logScale) { lv = Math.log10(lv); if (lv < 0 || Double.isInfinite(lv)) lv = 0; values[i][j] = lv; //values[r.nextInt(width)][r.nextInt(height)] = lv; } else { values[i][j] = lv; } if (lv > maxValue) maxValue = lv; } // This should never happen, but just for correctness if (maxValue == 0) return false; // Normalize all values for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) { values[i][j] /= maxValue; } // prepare a bitmap of required size BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); // draw image points for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) { Color pointColor = paletteType.getColor(values[i][j]); image.setRGB(i, height - j - 1, pointColor.getRGB()); } // if we are zoomed out, save the values if ((imageRTMin == totalRTRange.getMin()) && (imageRTMax == totalRTRange.getMax()) && (imageMZMin == totalMZRange.getMin()) && (imageMZMax == totalMZRange.getMax())) { zoomOutBitmap = image; } // Paint image g2.drawImage(image, x, y, null); Date renderFinishTime = new Date(); logger.finest("Finished rendering 2D visualizer, " + (renderFinishTime.getTime() - renderStartTime.getTime()) + " ms"); return true; }
From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java
public static BufferedImage flipImageHorizontal(BufferedImage img) { if (img == null) { return null; }/* www .ja v a2 s.c om*/ if (img.getType() == 0) { img = convertToARGB(img); } BufferedImage out = new BufferedImage(img.getWidth(), img.getHeight(), img.getType()); for (int y = 0; y < out.getHeight(); y++) { for (int x = 0; x < out.getWidth(); x++) { out.setRGB(x, y, img.getRGB(img.getWidth() - x - 1, y)); } } return out; }