List of usage examples for java.awt RenderingHints put
public Object put(Object key, Object value)
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D twoD = (Graphics2D) g; RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); twoD.setRenderingHints(rh);//from ww w. ja v a2 s. c o m twoD.setColor(Color.BLACK); twoD.drawString(raised, 5, 90); }
From source file:ColorFadingAnimation.java
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(new Color(50, 50, 50)); RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHints(rh);/* w ww . j av a 2 s . c o m*/ g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha_rectangle)); g2d.fill(rect); }
From source file:TimerBasedAnimation.java
public void paint(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setRenderingHints(rh);/*from ww w .j a v a 2s . co m*/ Dimension size = getSize(); if (initialize) { reset(size.width, size.height); initialize = false; } this.step(size.width, size.height); render(size.width, size.height, g2); }
From source file:FontRenderContextRenderingHints.java
public void paint(Graphics g) { Graphics2D g2D = (Graphics2D) g; int w = getSize().width; int h = getSize().height; RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); qualityHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2D.setRenderingHints(qualityHints); AffineTransform at = new AffineTransform(); at.setToTranslation(-300, -400);/* w w w . jav a 2 s . c om*/ at.shear(-0.5, 0.0); FontRenderContext frc = new FontRenderContext(at, false, false); TextLayout tl = new TextLayout("World!", font, frc); Shape outline = tl.getOutline(null); g2D.setColor(Color.blue); BasicStroke wideStroke = new BasicStroke(2.0f); g2D.setStroke(wideStroke); g2D.draw(outline); }
From source file:org.kuali.mobility.people.service.PeopleServiceImpl.java
@Override public BufferedImage generateObfuscatedImage(String text) { int width = 250; int height = 25; BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = bufferedImage.createGraphics(); Font font = new Font("Arial", Font.PLAIN, 14); g2d.setFont(font);/*from www . j a v a 2s . c o m*/ RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHints(rh); Paint bg = new Color(255, 255, 255); g2d.setPaint(bg); g2d.fillRect(0, 0, width, height); int x = 0; int y = height - 7; Paint textPaint = new Color(0, 0, 0); g2d.setPaint(textPaint); g2d.drawString(text, x, y); g2d.dispose(); return bufferedImage; }
From source file:com.hmsinc.epicenter.spatial.render.SpatialScanRenderer.java
/** * @param context/* w w w . j a va2 s.c om*/ * @return */ private BufferedImage renderImage(final MapContext context, int width, int height) { logger.trace("Image width: {} height: {}", width, height); final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final Graphics2D graphics2D = (Graphics2D) image.getGraphics(); final GTRenderer renderer = new StreamingRenderer(); final RenderingHints h = new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); h.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); h.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); h.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); h.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); renderer.setJava2DHints(h); renderer.setContext(context); renderer.paint(graphics2D, new Rectangle(width, height), context.getAreaOfInterest()); return image; }
From source file:ch.entwine.weblounge.preview.jai.JAIPreviewGenerator.java
/** * Resizes the given image to what is defined by the image style and writes * the result to the output stream./*from ww w.ja v a 2 s .c o m*/ * * @param is * the input stream * @param os * the output stream * @param format * the image format * @param style * the style * @throws IllegalArgumentException * if the image is in an unsupported format * @throws IllegalArgumentException * if the input stream is empty * @throws IOException * if reading from or writing to the stream fails * @throws OutOfMemoryError * if the image is too large to be processed in memory */ private void style(InputStream is, OutputStream os, String format, ImageStyle style) throws IllegalArgumentException, IOException, OutOfMemoryError { // Does the input stream contain any data? if (is.available() == 0) throw new IllegalArgumentException("Empty input stream was passed to image styling"); // Do we need to do any work at all? if (style == null || ImageScalingMode.None.equals(style.getScalingMode())) { logger.trace("No scaling needed, performing a noop stream copy"); IOUtils.copy(is, os); return; } SeekableStream seekableInputStream = null; RenderedOp image = null; try { // Load the image from the given input stream seekableInputStream = new FileCacheSeekableStream(is); image = JAI.create("stream", seekableInputStream); if (image == null) throw new IOException("Error reading image from input stream"); // Get the original image size int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); // Resizing float scale = ImageStyleUtils.getScale(imageWidth, imageHeight, style); RenderingHints scaleHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); scaleHints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); scaleHints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); scaleHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); int scaledWidth = Math.round(scale * image.getWidth()); int scaledHeight = Math.round(scale * image.getHeight()); int cropX = 0; int cropY = 0; // If either one of scaledWidth or scaledHeight is < 1.0, then // the scale needs to be adapted to scale to 1.0 exactly and accomplish // the rest by cropping. if (scaledWidth < 1.0f) { scale = 1.0f / imageWidth; scaledWidth = 1; cropY = imageHeight - scaledHeight; scaledHeight = Math.round(imageHeight * scale); } else if (scaledHeight < 1.0f) { scale = 1.0f / imageHeight; scaledHeight = 1; cropX = imageWidth - scaledWidth; scaledWidth = Math.round(imageWidth * scale); } if (scale > 1.0) { ParameterBlock scaleParams = new ParameterBlock(); scaleParams.addSource(image); scaleParams.add(scale).add(scale).add(0.0f).add(0.0f); scaleParams.add(Interpolation.getInstance(Interpolation.INTERP_BICUBIC_2)); image = JAI.create("scale", scaleParams, scaleHints); } else if (scale < 1.0) { ParameterBlock subsampleAverageParams = new ParameterBlock(); subsampleAverageParams.addSource(image); subsampleAverageParams.add(Double.valueOf(scale)); subsampleAverageParams.add(Double.valueOf(scale)); image = JAI.create("subsampleaverage", subsampleAverageParams, scaleHints); } // Cropping cropX = (int) Math.max(cropX, (float) Math.ceil(ImageStyleUtils.getCropX(scaledWidth, scaledHeight, style))); cropY = (int) Math.max(cropY, (float) Math.ceil(ImageStyleUtils.getCropY(scaledWidth, scaledHeight, style))); if ((cropX > 0 && Math.floor(cropX / 2.0f) > 0) || (cropY > 0 && Math.floor(cropY / 2.0f) > 0)) { ParameterBlock cropTopLeftParams = new ParameterBlock(); cropTopLeftParams.addSource(image); cropTopLeftParams.add(cropX > 0 ? ((float) Math.floor(cropX / 2.0f)) : 0.0f); cropTopLeftParams.add(cropY > 0 ? ((float) Math.floor(cropY / 2.0f)) : 0.0f); cropTopLeftParams.add(scaledWidth - Math.max(cropX, 0.0f)); // width cropTopLeftParams.add(scaledHeight - Math.max(cropY, 0.0f)); // height RenderingHints croppingHints = new RenderingHints(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(BorderExtender.BORDER_COPY)); image = JAI.create("crop", cropTopLeftParams, croppingHints); } // Write resized/cropped image encoded as JPEG to the output stream ParameterBlock encodeParams = new ParameterBlock(); encodeParams.addSource(image); encodeParams.add(os); encodeParams.add("jpeg"); JAI.create("encode", encodeParams); } catch (Throwable t) { if (t.getClass().getName().contains("ImageFormat")) { throw new IllegalArgumentException(t.getMessage()); } } finally { IOUtils.closeQuietly(seekableInputStream); if (image != null) image.dispose(); } }
From source file:com.AandR.beans.plotting.LinePlotPanel.LinePlotPanel.java
private ChartPanel createChartPanel() { JFreeChart xyChart = ChartFactory.createXYLineChart("f", "x", "y", plotSeries, PlotOrientation.VERTICAL, false, true, false);/*from w w w . j av a 2 s . co m*/ RenderingHints hints = xyChart.getRenderingHints(); hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); xyChart.setBackgroundPaint(Color.WHITE); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyChart.getXYPlot().getRenderer(); renderer.setBaseLinesVisible(isLineVisible); renderer.setBaseShapesVisible(isSymbolVisible); LegendTitle legend = new LegendTitle(renderer); legend.setPosition(RectangleEdge.BOTTOM); xyChart.addLegend(legend); xyChart.getXYPlot().getRangeAxis().setStandardTickUnits(createTickUnits()); //xyChart.getXYPlot().getRangeAxis().setStandardTickUnits(new StandardTickUnitSource()); xyChart.getXYPlot().getRangeAxis().setAutoRangeMinimumSize(1.0e-45); chartPanel = new ChartPanel(xyChart); JPopupMenu popup = chartPanel.getPopupMenu(); popup.remove(1); // removes separator popup.remove(1); // removes save as... popup.add(createLinePropMenu()); popup.add(createAxesPropMenu()); popup.addSeparator(); popup.add(createExportMenu()); return chartPanel; }
From source file:edu.ku.brc.specify.utilapps.ERDVisualizer.java
/** * @return//from w w w . j a v a 2 s .co m */ public static RenderingHints createTextRenderingHints() { RenderingHints renderingHints; //RenderingHints renderingHints1 = new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); RenderingHints renderingHints2 = new RenderingHints(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); //RenderingHints renderingHints3 = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); renderingHints = renderingHints2; Object value = RenderingHints.VALUE_TEXT_ANTIALIAS_ON; try { java.lang.reflect.Field declaredField = RenderingHints.class .getDeclaredField("VALUE_TEXT_ANTIALIAS_LCD_HRGB"); value = declaredField.get(null); } catch (Exception e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ERDVisualizer.class, e); // do nothing } renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, value); //renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); //renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP); //renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VRGB); return renderingHints; }
From source file:it.geosolutions.geobatch.destination.vulnerability.VulnerabilityComputation.java
/** * Method used for merging the input Rasters into a 2 images, one for human targets and the other for not human targets * // ww w.j a v a 2 s . c o m * @param humanTargets * @param notHumanTargets * @param bandPerTargetH * @param bandPerTargetNH * @throws IOException * @throws java.awt.geom.NoninvertibleTransformException * @throws TransformException * @throws MismatchedDimensionException */ public RenderedImage[] rasterCalculation(Map<Integer, TargetInfo> bandPerTargetH, Map<Integer, TargetInfo> bandPerTargetNH) throws IOException, java.awt.geom.NoninvertibleTransformException, MismatchedDimensionException, TransformException { // Initialization of the images RenderedImage humanTargets = null; RenderedImage notHumanTargets = null; String basePath = System.getProperty(RASTER_PATH_PROP, ""); if (!basePath.equals("")) { basePath = basePath + File.separator + codicePartner; } // Read of the resources Map vulnerabilityConf = (Map) readResourceFromXML("/vulnerability.xml"); // Vulnerability engine used for extracting the Targets VulnerabilityStatsEngine vsengine = new VulnerabilityStatsEngine(basePath, vulnerabilityConf, dataStore, DISTANCE_TYPE_NAME, pixelArea); // Target Map Map<String, TargetInfo> targetInfo = vsengine.getTargetInfo(); /* * Creation of 2 images: one for the HUMAN TARGETS and the other for NOT HUMAN TARGETS */ // List of Human Targets List<RenderedImage> humanList = new ArrayList<RenderedImage>(); // List of Not Human Targets List<RenderedImage> notHumanList = new ArrayList<RenderedImage>(); // Counters indicating which band is associated to the TargetInfo and // Image int humanBandCounter = 0; int notHumanBandCounter = 0; // Iterator on all the targets Iterator<String> rasterIter = targetInfo.keySet().iterator(); // Initializations of the parameters for merging the input rasters Envelope2D globalBBOXHuman = null; Envelope2D globalBBOXNotHuman = null; List<AffineTransform> tfHuman = new ArrayList<AffineTransform>(); List<AffineTransform> tfNotHuman = new ArrayList<AffineTransform>(); AffineTransform g2WHuman = null; AffineTransform g2WNotHuman = null; // Cycle on all the rasters while (rasterIter.hasNext()) { // save the ID of this target String targetID = rasterIter.next(); // Load the target manager, init its status and check if the actual // distance is a valid distance for it TargetInfo info = targetInfo.get(targetID); // Getting of the transformation parameters GridGeometry2D gg2D = info.getGG2D(); Envelope2D envelope = gg2D.getEnvelope2D(); AffineTransform w2g = (AffineTransform) gg2D.getCRSToGrid2D(PixelOrientation.UPPER_LEFT); // getting information about current Target TargetManager manager = info.getManager(); // Image associated to the current target RenderedImage newImage = info.getRaster(); // Image data type int imgDataType = newImage.getSampleModel().getDataType(); // Check if the image really exists if (newImage != null) { // If the target is human if (manager.isHumanTarget()) { // Other check for ensuring the target is correct if (imgDataType != DataBuffer.TYPE_FLOAT) { System.out.println("Wrong data type"); } // perform union if (globalBBOXHuman == null) { globalBBOXHuman = new Envelope2D(envelope); } else { globalBBOXHuman.include(envelope); } // Selection of the first g2w transform as the global one if (g2WHuman == null) { g2WHuman = (AffineTransform) gg2D.getGridToCRS2D(PixelOrientation.UPPER_LEFT); } // Creation of the transformation from destination Raster space to source Raster space AffineTransform temp = new AffineTransform(w2g); temp.concatenate(g2WHuman); tfHuman.add(temp); // Addition of the TargetInfo of this target bandPerTargetH.put(humanBandCounter, info); // Update of the bandCounter humanBandCounter++; // Addition of the image to the associated list humanList.add(newImage); } else { // Other check for ensuring the target is correct if (imgDataType != DataBuffer.TYPE_BYTE) { System.out.println("Wrong data type"); } // perform union if (globalBBOXNotHuman == null) { globalBBOXNotHuman = envelope; } else { globalBBOXNotHuman.include(envelope); } // Selection of the first g2w transform as the global one if (g2WNotHuman == null) { g2WNotHuman = (AffineTransform) gg2D.getGridToCRS2D(PixelOrientation.UPPER_LEFT); } // Creation of the transformation from destination Raster space to source Raster space AffineTransform temp = new AffineTransform(w2g); temp.concatenate(g2WNotHuman); tfNotHuman.add(temp); // Addition of the TargetInfo of this target bandPerTargetNH.put(notHumanBandCounter, info); // Update of the bandCounter notHumanBandCounter++; // Addition of the image to the associated list notHumanList.add(newImage); } } } // computing final raster space for the two targets GridGeometry2D humanGG2D = new GridGeometry2D(PixelInCell.CELL_CORNER, new AffineTransform2D(g2WHuman), globalBBOXHuman, null); globalBBOXHuman = humanGG2D.getEnvelope2D(); // take into account integer pixel roundings GridGeometry2D noHumanGG2D = new GridGeometry2D(PixelInCell.CELL_CORNER, new AffineTransform2D(g2WNotHuman), globalBBOXNotHuman, null); globalBBOXNotHuman = noHumanGG2D.getEnvelope2D(); // take into account integer pixel roundings // BandMerge of the images RenderedImage[] imagesHuman = new RenderedImage[humanList.size()]; RenderedImage[] imagesNotHuman = new RenderedImage[notHumanList.size()]; // Setting of the final layout ImageLayout layoutH = new ImageLayout2(); GridEnvelope2D gridRange2D = humanGG2D.getGridRange2D(); layoutH.setMinX(gridRange2D.x); layoutH.setMinY(gridRange2D.y); layoutH.setWidth(gridRange2D.width); layoutH.setHeight(gridRange2D.height); // Definition of the TileCache RenderingHints hintsH = new RenderingHints(JAI.KEY_TILE_CACHE, JAI.getDefaultInstance().getTileCache()); // Setting of the layout as hint hintsH.put(JAI.KEY_IMAGE_LAYOUT, layoutH); // Merging of the input human targets humanTargets = BandMergeDescriptor.create(null, 0, hintsH, tfHuman, humanList.toArray(imagesHuman)); // Setting of the final layout ImageLayout layoutNH = new ImageLayout2(); gridRange2D = noHumanGG2D.getGridRange2D(); layoutNH.setMinX(gridRange2D.x); layoutNH.setMinY(gridRange2D.y); layoutNH.setWidth(gridRange2D.width); layoutNH.setHeight(gridRange2D.height); // Definition of the TileCache RenderingHints hintsNH = new RenderingHints(JAI.KEY_TILE_CACHE, JAI.getDefaultInstance().getTileCache()); hintsNH.put(JAI.KEY_IMAGE_LAYOUT, layoutNH); // Merging of the input not human targets notHumanTargets = BandMergeDescriptor.create(null, 0, hintsNH, tfNotHuman, notHumanList.toArray(imagesNotHuman)); // cache the final images humanTargets = NullDescriptor.create(humanTargets, new RenderingHints(JAI.KEY_TILE_CACHE, JAI.getDefaultInstance().getTileCache())); notHumanTargets = NullDescriptor.create(notHumanTargets, new RenderingHints(JAI.KEY_TILE_CACHE, JAI.getDefaultInstance().getTileCache())); // Clearing of the initial lists notHumanList.clear(); humanList.clear(); // create a new array of the new images return new RenderedImage[] { humanTargets, notHumanTargets }; }