List of usage examples for java.awt.image BufferedImage TYPE_INT_RGB
int TYPE_INT_RGB
To view the source code for java.awt.image BufferedImage TYPE_INT_RGB.
Click Source Link
From source file:ImageBouncer.java
public void setImageType(String s) { int type = BufferedImage.TYPE_CUSTOM; if (s.equals("TYPE_INT_RGB")) type = BufferedImage.TYPE_INT_RGB; else if (s.equals("TYPE_INT_ARGB")) type = BufferedImage.TYPE_INT_ARGB; else if (s.equals("TYPE_INT_ARGB_PRE")) type = BufferedImage.TYPE_INT_ARGB_PRE; else if (s.equals("TYPE_3BYTE_BGR")) type = BufferedImage.TYPE_3BYTE_BGR; else if (s.equals("TYPE_BYTE_GRAY")) type = BufferedImage.TYPE_BYTE_GRAY; else if (s.equals("TYPE_USHORT_GRAY")) type = BufferedImage.TYPE_USHORT_GRAY; else if (s.equals("TYPE_USHORT_555_RGB")) type = BufferedImage.TYPE_USHORT_565_RGB; else if (s.equals("TYPE_USHORT_565_RGB")) type = BufferedImage.TYPE_USHORT_565_RGB; else {//from w w w.ja va2 s . c o m System.out.println("Unrecognized type."); return; } image = makeBufferedImage(mOriginalImage, type); }
From source file:com.galenframework.utils.GalenUtils.java
public static File makeFullScreenshot(WebDriver driver) throws IOException, InterruptedException { // scroll up first scrollVerticallyTo(driver, 0);//from ww w.ja v a2 s . co m byte[] bytes = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES); BufferedImage image = ImageIO.read(new ByteArrayInputStream(bytes)); int capturedWidth = image.getWidth(); int capturedHeight = image.getHeight(); long longScrollHeight = (Long) ((JavascriptExecutor) driver).executeScript( "return Math.max(" + "document.body.scrollHeight, document.documentElement.scrollHeight," + "document.body.offsetHeight, document.documentElement.offsetHeight," + "document.body.clientHeight, document.documentElement.clientHeight);"); Double devicePixelRatio = ((Number) ((JavascriptExecutor) driver) .executeScript(JS_RETRIEVE_DEVICE_PIXEL_RATIO)).doubleValue(); int scrollHeight = (int) longScrollHeight; File file = File.createTempFile("screenshot", ".png"); int adaptedCapturedHeight = (int) (((double) capturedHeight) / devicePixelRatio); BufferedImage resultingImage; if (Math.abs(adaptedCapturedHeight - scrollHeight) > 40) { int scrollOffset = adaptedCapturedHeight; int times = scrollHeight / adaptedCapturedHeight; int leftover = scrollHeight % adaptedCapturedHeight; final BufferedImage tiledImage = new BufferedImage(capturedWidth, (int) (((double) scrollHeight) * devicePixelRatio), BufferedImage.TYPE_INT_RGB); Graphics2D g2dTile = tiledImage.createGraphics(); g2dTile.drawImage(image, 0, 0, null); int scroll = 0; for (int i = 0; i < times - 1; i++) { scroll += scrollOffset; scrollVerticallyTo(driver, scroll); BufferedImage nextImage = ImageIO.read( new ByteArrayInputStream(((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES))); g2dTile.drawImage(nextImage, 0, (i + 1) * capturedHeight, null); } if (leftover > 0) { scroll += scrollOffset; scrollVerticallyTo(driver, scroll); BufferedImage nextImage = ImageIO.read( new ByteArrayInputStream(((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES))); BufferedImage lastPart = nextImage.getSubimage(0, nextImage.getHeight() - (int) (((double) leftover) * devicePixelRatio), nextImage.getWidth(), leftover); g2dTile.drawImage(lastPart, 0, times * capturedHeight, null); } scrollVerticallyTo(driver, 0); resultingImage = tiledImage; } else { resultingImage = image; } if (GalenConfig.getConfig().shouldAutoresizeScreenshots()) { try { resultingImage = GalenUtils.resizeScreenshotIfNeeded(driver, resultingImage); } catch (Exception ex) { LOG.trace("Couldn't resize screenshot", ex); } } ImageIO.write(resultingImage, "png", file); return file; }
From source file:org.n52.server.sos.generator.DiagramGenerator.java
/** * Produce legend.// w w w . j a va 2 s . c o m * * @param options * the options * @param out * the out * @throws OXFException * the oXF exception */ public void createLegend(DesignOptions options, OutputStream out) throws OXFException, IOException { int topMargin = 10; int leftMargin = 30; int iconWidth = 15; int iconHeight = 15; int verticalSpaceBetweenEntries = 20; int horizontalSpaceBetweenIconAndText = 15; DesignDescriptionList ddList = buildUpDesignDescriptionList(options); int width = 800; int height = topMargin + (ddList.size() * (iconHeight + verticalSpaceBetweenEntries)); BufferedImage legendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D legendGraphics = legendImage.createGraphics(); legendGraphics.setColor(Color.white); legendGraphics.fillRect(0, 0, width, height); int offset = 0; for (RenderingDesign dd : ddList.getAllDesigns()) { int yPos = topMargin + offset * iconHeight + offset * verticalSpaceBetweenEntries; // icon: legendGraphics.setColor(dd.getColor()); legendGraphics.fillRect(leftMargin, yPos, iconWidth, iconHeight); // text: legendGraphics.setColor(Color.black); legendGraphics.drawString(dd.getFeature().getLabel() + " - " + dd.getLabel(), leftMargin + iconWidth + horizontalSpaceBetweenIconAndText, yPos + iconHeight); offset++; } // draw legend into image: JPEGEncodeParam p = new JPEGEncodeParam(); p.setQuality(1f); ImageEncoder encoder = ImageCodec.createImageEncoder("jpeg", out, p); encoder.encode(legendImage); }
From source file:com.neophob.sematrix.core.generator.Textwriter.java
/** * create image.// ww w .ja v a2 s . c o m * * @param text the text */ public void createTextImage(String text) { //only load if needed if (StringUtils.equals(text, this.text)) { return; } this.text = text; BufferedImage img = new BufferedImage(TEXT_BUFFER_X_SIZE, internalBufferYSize, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = img.createGraphics(); FontRenderContext frc = g2.getFontRenderContext(); TextLayout layout = new TextLayout(text, font, frc); Rectangle2D rect = layout.getBounds(); int h = (int) (0.5f + rect.getHeight()); //head and tailing space maxXPos = (int) (0.5f + rect.getWidth()) + 2 * internalBufferXSize; int ypos = internalBufferYSize - (internalBufferYSize - h) / 2; img = new BufferedImage(maxXPos, internalBufferYSize, BufferedImage.TYPE_BYTE_GRAY); g2 = img.createGraphics(); g2.setColor(new Color(128)); g2.setFont(font); g2.setClip(0, 0, maxXPos, internalBufferYSize); g2.drawString(text, internalBufferXSize, ypos); DataBufferByte dbi = (DataBufferByte) img.getRaster().getDataBuffer(); byte[] textBuffer = dbi.getData(); g2.dispose(); xofs = 0; textAsImage = new int[maxXPos * internalBufferYSize]; for (int i = 0; i < textAsImage.length; i++) { if (textBuffer[i] > 10) { textAsImage[i] = 127; } else { textAsImage[i] = 0; } } //clear internalbuffer Arrays.fill(this.internalBuffer, 0); }
From source file:de.anycook.upload.UploadHandler.java
/** * speichert eine kleine Version des Bildes * * @param image BufferedImage// ww w . j a v a 2 s . c o m * @param filename Name der zu erzeugenden Datei */ private void saveSmallImage(BufferedImage image, String filename) throws IOException { int height = image.getHeight(); int width = image.getWidth(); double imageRatio = (double) width / (double) height; int xtranslate = 0; int ytranslate = 0; if (imageRatio > 1) { xtranslate = (width - height) / 2; } else { ytranslate = (height - width) / 2; } BufferedImage tempImage = image.getSubimage(xtranslate, ytranslate, width - xtranslate * 2, height - ytranslate * 2); BufferedImage newImage = new BufferedImage(smallSize, smallSize, BufferedImage.TYPE_INT_RGB); newImage.getGraphics().drawImage(tempImage.getScaledInstance(smallSize, smallSize, Image.SCALE_SMOOTH), 0, 0, null); imageSaver.save("small/", filename, newImage); }
From source file:org.n52.oxf.render.sos.ProportionalCircleMapRenderer.java
private Image renderLegend(ObservationSeriesCollection obsValues, String observedProperty) { double lowestValue = (Double) obsValues.getMinimum(0); double highestValue = (Double) obsValues.getMaximum(0); double classDistance = (highestValue - lowestValue) / (NUMBER_OF_CLASSES - 2); int dotSizeDistance = (MAX_DOT_SIZE - MIN_DOT_SIZE) / (NUMBER_OF_CLASSES - 2); BufferedImage image = new BufferedImage(LEGEND_WIDTH, LEGEND_HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); // draw white background: g.setColor(Color.WHITE);/*from w w w .jav a 2 s .co m*/ g.fillRect(0, 0, LEGEND_WIDTH, LEGEND_HEIGHT); // draw information: observedProperty = observedProperty.split(":")[observedProperty.split(":").length - 1]; g.setColor(Color.BLACK); g.drawString("Observed Property: '" + observedProperty + "'", 25, 25); for (int i = 1; i <= NUMBER_OF_CLASSES; i++) { // draw text: int x_stringLocation = 100; int y_location = i * 60; g.setColor(Color.BLACK); DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(Locale.GERMAN); df.applyPattern("#,###,##0.00"); double lowerBorder = lowestValue + classDistance * (i - 1); double upperBorder = lowestValue + classDistance * i; g.drawString(i + ". class: " + df.format(lowerBorder) + " - " + df.format(upperBorder), x_stringLocation, y_location + 10); // draw symbol: int x_symbolLocation = 30; g.setColor(POINT_INNER_COLOR); g.fillOval(x_symbolLocation, y_location, i * dotSizeDistance, i * dotSizeDistance); } return image; }
From source file:CustomAlphaTest.java
public CustomAlphaTest() { try {/*from w ww.j a v a 2 s . c om*/ // HACK: // if we are running as an Applet // the getWorkingDirectory() call will throw an NPE // as we cannot call getCodeBase until "start" has been called // (below). m_Alpha = new FileAlpha(new URL(getWorkingDirectory(), "values.xls")); m_Image = new BufferedImage(m_kWidth, m_kHeight, BufferedImage.TYPE_INT_RGB); buildUi(); initJava3d(); } catch (Exception e) { } }
From source file:com.liusoft.dlog4j.util.ImageUtils.java
/** * ???//from w w w. j av a 2 s .c o m * ????? * 3: 180 * 6: 90 * 8: 27090 * @param img_fn * @param orient * @throws IOException */ public static boolean rotateImage(String img_fn, int orient, String dest_fn) throws IOException { double radian = 0; switch (orient) { case 3: radian = 180.0; break; case 6: radian = 90.0; break; case 8: radian = 270.0; break; default: return false; } BufferedImage old_img = (BufferedImage) ImageIO.read(new File(img_fn)); int width = old_img.getWidth(); int height = old_img.getHeight(); BufferedImage new_img = new BufferedImage(height, width, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = new_img.createGraphics(); AffineTransform origXform = g2d.getTransform(); AffineTransform newXform = (AffineTransform) (origXform.clone()); // center of rotation is center of the panel double xRot = 0; double yRot = 0; switch (orient) { case 3: xRot = width / 2.0; yRot = height / 2.0; case 6: xRot = height / 2.0; yRot = xRot; break; case 8: xRot = width / 2.0; yRot = xRot; break; default: return false; } newXform.rotate(Math.toRadians(radian), xRot, yRot); g2d.setTransform(newXform); // draw image centered in panel g2d.drawImage(old_img, 0, 0, null); // Reset to Original g2d.setTransform(origXform); FileOutputStream out = new FileOutputStream(dest_fn); try { ImageIO.write(new_img, "JPG", out); } finally { out.close(); } return true; }
From source file:algorithm.ImageInformationEmbeddingFrame.java
/** * Create empty image with enough capacity to embed the payload * /* w w w . j av a 2 s. c o m*/ * @param carrier * @param payload * @return image for payload * @throws IOException */ private BufferedImage createPayloadImage(File carrier, File payload) throws IOException { BufferedImage carrierImage = ImageIO.read(carrier); byte[] payloadBytes = FileUtils.readFileToByteArray(payload); int neededPayloadHeight = getNeededHeight(carrierImage.getWidth(), payloadBytes.length); return new BufferedImage(carrierImage.getWidth(), neededPayloadHeight, BufferedImage.TYPE_INT_RGB); }
From source file:PNGDecoder.java
/** * Decodes image from an input stream passed into constructor. * @return a BufferedImage object//from w w w . ja va2s. c om * @throws IOException */ public BufferedImage decode() throws IOException { byte[] id = read(12); checkEquality(id, new byte[] { -119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13 }); byte[] ihdr = read(4); checkEquality(ihdr, "IHDR".getBytes()); int width = readInt(); int height = readInt(); BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); byte[] head = read(5); int mode; if (compare(head, new byte[] { 1, 0, 0, 0, 0 })) { mode = PNGEncoder.BW_MODE; } else if (compare(head, new byte[] { 8, 0, 0, 0, 0 })) { mode = PNGEncoder.GREYSCALE_MODE; } else if (compare(head, new byte[] { 8, 2, 0, 0, 0 })) { mode = PNGEncoder.COLOR_MODE; } else { throw (new RuntimeException("Format error")); } readInt();//!!crc int size = readInt(); byte[] idat = read(4); checkEquality(idat, "IDAT".getBytes()); byte[] data = read(size); Inflater inflater = new Inflater(); inflater.setInput(data, 0, size); int color; try { switch (mode) { case PNGEncoder.BW_MODE: { int bytes = (int) (width / 8); if ((width % 8) != 0) { bytes++; } byte colorset; byte[] row = new byte[bytes]; for (int y = 0; y < height; y++) { inflater.inflate(new byte[1]); inflater.inflate(row); for (int x = 0; x < bytes; x++) { colorset = row[x]; for (int sh = 0; sh < 8; sh++) { if (x * 8 + sh >= width) { break; } if ((colorset & 0x80) == 0x80) { result.setRGB(x * 8 + sh, y, Color.white.getRGB()); } else { result.setRGB(x * 8 + sh, y, Color.black.getRGB()); } colorset <<= 1; } } } } break; case PNGEncoder.GREYSCALE_MODE: { byte[] row = new byte[width]; for (int y = 0; y < height; y++) { inflater.inflate(new byte[1]); inflater.inflate(row); for (int x = 0; x < width; x++) { color = row[x]; result.setRGB(x, y, (color << 16) + (color << 8) + color); } } } break; case PNGEncoder.COLOR_MODE: { byte[] row = new byte[width * 3]; for (int y = 0; y < height; y++) { inflater.inflate(new byte[1]); inflater.inflate(row); for (int x = 0; x < width; x++) { result.setRGB(x, y, ((row[x * 3 + 0] & 0xff) << 16) + ((row[x * 3 + 1] & 0xff) << 8) + ((row[x * 3 + 2] & 0xff))); } } } } } catch (DataFormatException e) { throw (new RuntimeException("ZIP error" + e)); } readInt();//!!crc readInt();//0 byte[] iend = read(4); checkEquality(iend, "IEND".getBytes()); readInt();//!!crc in.close(); return (result); }