List of usage examples for java.awt Graphics2D drawImage
public abstract void drawImage(BufferedImage img, BufferedImageOp op, int x, int y);
From source file:eu.udig.style.advanced.utils.Utilities.java
/** * Creates an image from a set of {@link RuleWrapper}s. * /*from w w w . ja v a 2 s.co m*/ * @param rulesWrapperList the list of rules wrapper. * @param width the image width. * @param height the image height. * @return the new created {@link BufferedImage}. */ public static BufferedImage lineRulesWrapperToImage(final List<RuleWrapper> rulesWrapperList, int width, int height) { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = image.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (RuleWrapper rule : rulesWrapperList) { BufferedImage tmpImage = Utilities.lineRuleWrapperToImage(rule, width, height); g2d.drawImage(tmpImage, 0, 0, null); } g2d.dispose(); return image; }
From source file:eu.udig.style.advanced.utils.Utilities.java
/** * Creates an image from a set of {@link RuleWrapper}s. * //from ww w. j av a 2s .com * @param rulesWrapperList the list of rules wrapper. * @param width the image width. * @param height the image height. * @return the new created {@link BufferedImage}. */ public static BufferedImage polygonRulesWrapperToImage(final List<RuleWrapper> rulesWrapperList, int width, int height) { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = image.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (RuleWrapper rule : rulesWrapperList) { BufferedImage tmpImage = Utilities.polygonRuleWrapperToImage(rule, width, height); g2d.drawImage(tmpImage, 0, 0, null); } g2d.dispose(); return image; }
From source file:eu.udig.style.advanced.utils.Utilities.java
/** * Creates an image from a set of {@link RuleWrapper}s. * //from www . jav a 2 s .co m * @param ruleWrapperList the list of rule wrappers. * @param width the image width. * @param height the image height. * @return the new created {@link BufferedImage}. */ public static BufferedImage pointRulesWrapperToImage(final List<RuleWrapper> ruleWrapperList, int width, int height) { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = image.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (RuleWrapper ruleWrapper : ruleWrapperList) { BufferedImage tmpImage = Utilities.pointRuleWrapperToImage(ruleWrapper, width, height); g2d.drawImage(tmpImage, 0, 0, null); } g2d.dispose(); return image; }
From source file:AlphaCompositeSRCOUT.java
public void paint(Graphics g) { Graphics2D g2D = (Graphics2D) g; int w = getSize().width; int h = getSize().height; BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D big = bi.createGraphics(); ac = AlphaComposite.getInstance(compositeRule, alphaValue); big.setColor(Color.red);//from w w w . j a v a2 s . c om big.drawString("Destination", w / 4, h / 4); big.fill(new Ellipse2D.Double(0, h / 3, 2 * w / 3, h / 3)); big.setColor(Color.blue); big.drawString("Source", 3 * w / 4, h / 4); big.setComposite(ac); big.fill(new Ellipse2D.Double(w / 3, h / 3, 2 * w / 3, h / 3)); g2D.drawImage(bi, null, 0, 0); }
From source file:com.celements.photo.image.GenerateThumbnail.java
BufferedImage convertImageToBufferedImage(Image thumbImg, String watermark, String copyright, Color defaultBg) { BufferedImage thumb = new BufferedImage(thumbImg.getWidth(null), thumbImg.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = thumb.createGraphics(); if (defaultBg != null) { g2d.setColor(defaultBg);//from ww w.ja va 2 s. c om g2d.fillRect(0, 0, thumbImg.getWidth(null), thumbImg.getHeight(null)); } g2d.drawImage(thumbImg, 0, 0, null); if ((watermark != null) && (!watermark.equals(""))) { drawWatermark(watermark, g2d, thumb.getWidth(), thumb.getHeight()); } if ((copyright != null) && (!copyright.equals(""))) { drawCopyright(copyright, g2d, thumb.getWidth(), thumb.getHeight()); } mLogger.info("thumbDimensions: " + thumb.getHeight() + "x" + thumb.getWidth()); return thumb; }
From source file:org.messic.server.facade.controllers.pages.CaptchaController.java
@ApiMethod(path = "/captcha", verb = ApiVerb.GET, description = "Get a captcha", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE }) @ApiErrors(apierrors = { @ApiError(code = UnknownMessicRESTException.VALUE, description = "Unknown error") }) @RequestMapping(value = "", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK)//w w w . ja va 2 s.co m @ResponseBody @ApiResponseObject public Captcha getCaptcha() throws UnknownMessicRESTException { try { UUID idOne = UUID.randomUUID(); // create the image with the text BufferedImage bi = service.getImageChallengeForID(idOne.toString()); BufferedImage bi2 = Util.ImagedeepCopy(bi); Graphics2D g2d = (Graphics2D) bi.getGraphics(); float alpha = 0.25f; int type = AlphaComposite.SRC_OVER; AlphaComposite composite = AlphaComposite.getInstance(type, alpha); g2d.setComposite(composite); final int Min = 5; final int Max = 30; int random1 = Min + (int) (Math.random() * ((Max - Min) + 1)); int random2 = Min + (int) (Math.random() * ((Max - Min) + 1)); g2d.drawImage(bi2, random1, random2, null); alpha = 0.80f; type = AlphaComposite.SRC_OVER; composite = AlphaComposite.getInstance(type, alpha); g2d.setComposite(composite); int MinX = 0; int MaxX = bi.getWidth(); int MinY = 0; int MaxY = bi.getHeight(); g2d.setColor(Color.black); for (int i = 0; i < random2; i++) { int random3 = MinX + (int) (Math.random() * ((MaxX - MinX) + 1)); int random4 = MinX + (int) (Math.random() * ((MaxX - MinX) + 1)); int random5 = MinY + (int) (Math.random() * ((MaxY - MinY) + 1)); int random6 = MinY + (int) (Math.random() * ((MaxY - MinY) + 1)); g2d.drawLine(random3, random5, random4, random6); } Captcha result = new Captcha(); result.id = idOne.toString(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(bi, "jpg", baos); byte[] resultb64 = Base64.encode(baos.toByteArray()); result.captchaImage = new String(resultb64); return result; } catch (Exception e) { throw new UnknownMessicRESTException(e); } }
From source file:org.codice.alliance.imaging.chip.transformer.CatalogOutputAdapter.java
/** * @param image the BufferedImage to be converted. * @return a BinaryContent object containing the image data. * @throws IOException when the BufferedImage can't be written to temporary in-memory space. * @throws MimeTypeParseException thrown if the mime type is invalid *//*from w ww. j a va 2 s . co m*/ @SuppressWarnings("WeakerAccess") public BinaryContent getBinaryContent(BufferedImage image) throws IOException, MimeTypeParseException { validateArgument(image, "image"); BufferedImage rgbImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_3BYTE_BGR); Graphics2D graphics = rgbImage.createGraphics(); graphics.drawImage(image, 0, 0, null); InputStream fis = new ByteArrayInputStream(createJpg(rgbImage)); return new BinaryContentImpl(fis, new MimeType(IMAGE_JPG)); }
From source file:de.fhg.igd.mapviewer.server.wms.overlay.WMSTileOverlay.java
/** * @see AbstractTileOverlayPainter#repaintTile(int, int, int, int, * PixelConverter, int)//from w w w. j a va 2 s.c om */ @Override public BufferedImage repaintTile(int posX, int posY, int width, int height, PixelConverter converter, int zoom) { // the first converter isn't regarded as a new converter because it's // always the empty map boolean isNewConverter = lastConverter != null && !converter.equals(lastConverter); lastConverter = converter; if (!converter.supportsBoundingBoxes()) { if (isNewConverter) { handleError(Messages.WMSTileOverlay_0 + configuration.getName() + Messages.WMSTileOverlay_1); } return null; } synchronized (this) { if (capabilities == null) { try { capabilities = WMSUtil.getCapabilities(configuration.getBaseUrl()); } catch (WMSCapabilitiesException e) { log.error("Error getting WMS capabilities"); //$NON-NLS-1$ } } } if (capabilities != null) { int mapEpsg = converter.getMapEpsg(); WMSBounds box; synchronized (this) { if (capabilities.getSupportedSRS().contains("EPSG:" + mapEpsg)) { //$NON-NLS-1$ // same SRS supported } else { // SRS not supported if (isNewConverter) { StringBuilder message = new StringBuilder(); message.append(Messages.WMSTileOverlay_2); message.append(configuration.getName()); message.append(Messages.WMSTileOverlay_3); boolean init = true; for (String srs : capabilities.getSupportedSRS()) { if (init) { init = false; } else { message.append(", "); //$NON-NLS-1$ } message.append(srs); } handleError(message.toString()); } return null; } box = WMSUtil.getBoundingBox(capabilities, mapEpsg); } String srs = box.getSRS(); if (srs.startsWith("EPSG:")) { //$NON-NLS-1$ // determine format String format = null; Iterator<String> itFormat = supportedFormats.iterator(); synchronized (this) { while (format == null && itFormat.hasNext()) { String supp = itFormat.next(); if (capabilities.getFormats().contains(supp)) { format = supp; } } } if (format == null) { // no compatible format return null; } try { // check if tile lies within the bounding box int epsg = Integer.parseInt(srs.substring(5)); GeoPosition topLeft = converter.pixelToGeo(new Point(posX, posY), zoom); GeoPosition bottomRight = converter.pixelToGeo(new Point(posX + width, posY + height), zoom); // WMS bounding box BoundingBox wms = new BoundingBox(box.getMinX(), box.getMinY(), -1, box.getMaxX(), box.getMaxY(), 1); GeoConverter geotools = GeotoolsConverter.getInstance(); GeoPosition bbTopLeft = geotools.convert(topLeft, epsg); GeoPosition bbBottomRight = geotools.convert(bottomRight, epsg); double minX = Math.min(bbTopLeft.getX(), bbBottomRight.getX()); double minY = Math.min(bbTopLeft.getY(), bbBottomRight.getY()); double maxX = Math.max(bbTopLeft.getX(), bbBottomRight.getX()); double maxY = Math.max(bbTopLeft.getY(), bbBottomRight.getY()); BoundingBox tile = new BoundingBox(minX, minY, -1, maxX, maxY, 1); // check if bounding box and tile overlap if (wms.intersectsOrCovers(tile) || tile.covers(wms)) { WMSBounds bounds; if (epsg == mapEpsg) { bounds = new WMSBounds(srs, minX, minY, maxX, maxY); } else { // determine bounds for request minX = Math.min(topLeft.getX(), bottomRight.getX()); minY = Math.min(topLeft.getY(), bottomRight.getY()); maxX = Math.max(topLeft.getX(), bottomRight.getX()); maxY = Math.max(topLeft.getY(), bottomRight.getY()); bounds = new WMSBounds("EPSG:" + mapEpsg, minX, minY, maxX, maxY); //$NON-NLS-1$ } URI uri; synchronized (this) { uri = WMSUtil.getMapURI(capabilities, configuration, width, height, bounds, null, format, true); } Proxy proxy = ProxyUtil.findProxy(uri); InputStream in = uri.toURL().openConnection(proxy).getInputStream(); BufferedImage image = GraphicsUtilities.loadCompatibleImage(in); // apply transparency to the image BufferedImage result = GraphicsUtilities.createCompatibleTranslucentImage(image.getWidth(), image.getHeight()); Graphics2D g = result.createGraphics(); try { AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC, 0.5f); g.setComposite(ac); g.drawImage(image, 0, 0, null); } finally { g.dispose(); } return result; } } catch (Throwable e) { log.warn("Error painting WMS overlay", e); //$NON-NLS-1$ } } } return null; }
From source file:SimpleBufferedImageDemo.java
public void paint(Graphics g) { Graphics2D g2D = (Graphics2D) g; if (display) { if (buffered) { BufferedImage bi = (BufferedImage) createImage(getWidth(), getHeight()); // Draw into the memory buffer. for (int i = 0; i < getWidth(); i = i + displayImage.getWidth(this)) { for (int j = 0; j < getHeight(); j = j + displayImage.getHeight(this)) { bi.createGraphics().drawImage(displayImage, i, j, this); }//from w w w . j a v a 2 s . c o m } // Draw the buffered Image on to the screen g2D.drawImage(bi, 0, 0, this); } // This block of code draws the texture directly onto the screen. else if (!buffered) { for (int i = 0; i < getWidth(); i = i + displayImage.getWidth(this)) { for (int j = 0; j < getHeight(); j = j + displayImage.getHeight(this)) { g2D.drawImage(displayImage, i, j, this); } } } display = false; } else if (clear) { g2D.setColor(Color.white); g2D.clearRect(0, 0, getWidth(), getHeight()); clear = false; } }
From source file:com.krawler.esp.handlers.genericFileUpload.java
private BufferedImage toBufferedCompanyImage(Image image) { image = new ImageIcon(image).getImage(); BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g = bufferedImage.createGraphics(); // java.awt.Color transparent = new java.awt.Color(255, 255, 255, 1); // g.setColor(transparent); // int rule = java.awt.AlphaComposite.SRC_OVER; // // java.awt.AlphaComposite ac = java.awt.AlphaComposite.getInstance(rule,1); // g.setComposite(ac); // g.fillRect(0, 0, image.getWidth(null), image.getHeight(null)); g.drawImage(image, 0, 0, null); g.dispose();/*from w w w .j ava 2 s.c om*/ return bufferedImage; }