List of usage examples for java.awt RenderingHints RenderingHints
public RenderingHints(Map<Key, ?> init)
From source file:Main.java
/** * Returns map with rendering hints from a Graphics instance. * * @param g2d Graphics instance/* w w w .j a va 2 s.co m*/ * @param hintsToSave map of RenderingHint key-values * @param savedHints map to save hints into * @return map with rendering hints from a Graphics instance */ private static Map getRenderingHints(final Graphics2D g2d, final Map hintsToSave, Map savedHints) { if (savedHints == null) { savedHints = new RenderingHints(null); } else { savedHints.clear(); } if (hintsToSave == null || hintsToSave.size() == 0) { return savedHints; } final Set objects = hintsToSave.keySet(); for (final Object o : objects) { final RenderingHints.Key key = (RenderingHints.Key) o; final Object value = g2d.getRenderingHint(key); if (value != null) { savedHints.put(key, value); } } return savedHints; }
From source file:RenderQualityTest.java
public RenderQualityTestFrame() { setTitle("RenderQualityTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); buttonBox = new JPanel(); buttonBox.setLayout(new GridBagLayout()); hints = new RenderingHints(null); makeButtons("KEY_ANTIALIASING", "VALUE_ANTIALIAS_OFF", "VALUE_ANTIALIAS_ON"); makeButtons("KEY_TEXT_ANTIALIASING", "VALUE_TEXT_ANTIALIAS_OFF", "VALUE_TEXT_ANTIALIAS_ON"); makeButtons("KEY_FRACTIONALMETRICS", "VALUE_FRACTIONALMETRICS_OFF", "VALUE_FRACTIONALMETRICS_ON"); makeButtons("KEY_RENDERING", "VALUE_RENDER_SPEED", "VALUE_RENDER_QUALITY"); makeButtons("KEY_STROKE_CONTROL", "VALUE_STROKE_PURE", "VALUE_STROKE_NORMALIZE"); canvas = new RenderQualityComponent(); canvas.setRenderingHints(hints);//from w ww . j av a 2 s.co m add(canvas, BorderLayout.CENTER); add(buttonBox, BorderLayout.NORTH); }
From source file:net.sf.maltcms.common.charts.api.XYChartBuilder.java
/** * *//*from w ww. ja v a2 s .c o m*/ public XYChartBuilder() { plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); chart = new JFreeChart(plot); renderingHints = new RenderingHints(null); renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP); renderingHints.put(RenderingHints.KEY_TEXT_LCD_CONTRAST, 100); renderingHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); renderingHints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); renderingHints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE); renderingHints.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); renderingHints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); renderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); renderingHints.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); renderingHints.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); }
From source file:org.csstudio.utility.batik.SVGHandler.java
public SVGHandler(final SVGDocument doc, final Display display) { swtDisplay = display;//from w ww.j av a 2 s. co m useCache = Preferences.getUseCache(); imageBuffer = Collections.synchronizedList(new ArrayList<Image>()); maxBufferSize = Preferences.getCacheMaxSize(); listener = new Listener(); userAgent = createUserAgent(); renderingHints = new RenderingHints(null); DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); originalSVGDocument = (SVGDocument) DOMUtilities.deepCloneDocument(doc, impl); bridgeContext = createBridgeContext((SVGOMDocument) originalSVGDocument); isDynamicDocument = bridgeContext.isDynamicDocument(originalSVGDocument); // As we update the DOM, it has to be considered as dynamic bridgeContext.setDynamicState(BridgeContext.DYNAMIC); builder = new DynamicGVTBuilder(); // Build to calculate original dimension gvtRoot = builder.build(bridgeContext, originalSVGDocument); originalDimension = bridgeContext.getDocumentSize(); svgDocument = (SVGDocument) createWrapper(originalSVGDocument); builder.build(bridgeContext, svgDocument); buildElementsToUpdateList(bridgeContext, svgDocument); setAnimationLimitingFPS(10); }
From source file:SWTGraphics2D.java
/** * Creates a new instance./* www .ja v a 2 s. c o m*/ * * @param gc the graphics context. */ public SWTGraphics2D(GC gc) { super(); this.gc = gc; this.hints = new RenderingHints(null); this.composite = AlphaComposite.getInstance(AlphaComposite.SRC, 1.0f); }
From source file:org.jfree.experimental.swt.SWTGraphics2D.java
/** * Creates a new instance.//from w w w . j a va 2s .com * * @param gc the graphics context. */ public SWTGraphics2D(GC gc) { super(); this.gc = gc; this.hints = new RenderingHints(null); this.composite = AlphaComposite.getInstance(AlphaComposite.SRC, 1.0f); setStroke(new BasicStroke()); }
From source file:org.apache.fop.render.pcl.PCLDocumentHandler.java
private IFPainter createAllBitmapPainter() { double scale = gen.getMaximumBitmapResolution() / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION; Rectangle printArea = this.currentPageDefinition.getLogicalPageRect(); int bitmapWidth = (int) Math.ceil(UnitConv.mpt2px(printArea.width, gen.getMaximumBitmapResolution())); int bitmapHeight = (int) Math.ceil(UnitConv.mpt2px(printArea.height, gen.getMaximumBitmapResolution())); this.currentImage = createBufferedImage(bitmapWidth, bitmapHeight); Graphics2D graphics2D = this.currentImage.createGraphics(); if (!PCLGenerator.isJAIAvailable()) { RenderingHints hints = new RenderingHints(null); //These hints don't seem to make a difference :-( Not seeing any dithering on Sun Java. hints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); graphics2D.addRenderingHints(hints); }//w ww .ja v a 2 s. co m //Ensure white page background graphics2D.setBackground(Color.WHITE); graphics2D.clearRect(0, 0, bitmapWidth, bitmapHeight); graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); graphics2D.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); graphics2D.scale(scale / 1000f, scale / 1000f); graphics2D.translate(-printArea.x, -printArea.y); return new Java2DPainter(graphics2D, getContext(), getFontInfo()); }
From source file:SWTGraphics2D.java
/** * Replaces the existing hints with those contained in the specified * map. Note that, for now, this graphics context ignores all hints. * * @param hints the hints (<code>null</code> not permitted). * * @see #addRenderingHints(Map)/*from ww w . j a v a 2 s . co m*/ */ public void setRenderingHints(Map hints) { if (hints == null) { throw new NullPointerException("Null 'hints' argument."); } this.hints = new RenderingHints(hints); }
From source file:org.photovault.image.PhotovaultImage.java
/** Get the image, adjusted according to current parameters and scaled to a specified resolution./*from ww w . j av a 2 s .c o m*/ @param maxWidth Maximum width of the image in pixels. Image aspect ratio is preserved so actual width can be smaller than this. If maxWidth < 0, use actual width of original image instead. @param maxHeight Maximum height of the image in pixels. Image aspect ratio is preserved so actual height can be smaller than this. If maxHeight < 0, use actual height of original image instead. @param isLowQualityAllowed Specifies whether image quality can be traded off for speed/memory consumpltion optimizations. @return The image as RenderedImage */ public RenderedImage getRenderedImage(int maxWidth, int maxHeight, boolean isLowQualityAllowed) { /* Calculate the resolution we need for the original image based on crop & rotation information */ // First, calculate the size of whole inage after rotation double rotRad = rot * Math.PI / 180.0; double rotSin = Math.abs(Math.sin(rotRad)); double rotCos = Math.abs(Math.cos(rotRad)); double rotW = rotCos * getWidth() + rotSin * getHeight(); double rotH = rotSin * getWidth() + rotCos * getHeight(); // Size if full image was cropped double cropW = rotW * (cropMaxX - cropMinX); double cropH = rotH * (cropMaxY - cropMinY); if (maxWidth < 0) { maxWidth = (int) cropW; } if (maxHeight < 0) { maxHeight = (int) cropH; } double scaleW = maxWidth / cropW; double scaleH = maxHeight / cropH; // We are fitting cropped area to max{width x height} so we must use the // scale from dimension needing smallest scale. double scale = Math.min(scaleW, scaleH); double needW = getWidth() * scale; double needH = getHeight() * scale; RenderableOp original = getCorrectedImage((int) needW, (int) needH, isLowQualityAllowed); if (previousCorrectedImage != original) { buildPipeline(original); } int renderingWidth = maxWidth; int renderingHeight = (int) (renderingWidth * cropH / cropW); if (renderingHeight > maxHeight) { renderingHeight = maxHeight; renderingWidth = (int) (renderingHeight * cropW / cropH); } RenderingHints hints = new RenderingHints(null); hints.put(JAI.KEY_INTERPOLATION, new InterpolationBilinear()); RenderedImage rendered = null; if (lastRendering != null && lastRendering instanceof PlanarImage) { ((PlanarImage) lastRendering).dispose(); System.gc(); } if (saturated != null) { rendered = saturated.createScaledRendering(renderingWidth, renderingHeight, hints); lastRendering = rendered; } else { /* The image color model does not support saturation (e.g. b/w image), show the previous step instead. */ rendered = colorCorrected.createScaledRendering(renderingWidth, renderingHeight, hints); lastRendering = rendered; } fireNewRenderingEvent(); return rendered; }
From source file:org.photovault.image.PhotovaultImage.java
/** Get the image, adjusted according to current parameters and scaled with a specified factor.//w w w . ja v a 2s . co m @param scale Scaling compared to original image file. @param isLowQualityAllowed Specifies whether image quality can be traded off for speed/memory consumpltion optimizations. @return The image as RenderedImage */ public RenderedImage getRenderedImage(double scale, boolean isLowQualityAllowed) { /* Calculate the resolution we need for the original image based on crop & rotation information */ // First, calculate the size of whole inage after rotation double rotRad = rot * Math.PI / 180.0; double rotSin = Math.abs(Math.sin(rotRad)); double rotCos = Math.abs(Math.cos(rotRad)); double rotW = rotCos * getWidth() + rotSin * getHeight(); double rotH = rotSin * getWidth() + rotCos * getHeight(); // Size if full image was cropped double cropW = rotW * (cropMaxX - cropMinX); double cropH = rotH * (cropMaxY - cropMinY); RenderableOp original = getCorrectedImage((int) (getWidth() * scale), (int) (getHeight() * scale), isLowQualityAllowed); if (previousCorrectedImage != original) { buildPipeline(original); } RenderingHints hints = new RenderingHints(null); hints.put(JAI.KEY_INTERPOLATION, new InterpolationBilinear()); if (lastRendering != null && lastRendering instanceof PlanarImage) { ((PlanarImage) lastRendering).dispose(); System.gc(); } RenderedImage rendered = null; if (saturated != null) { rendered = saturated.createScaledRendering((int) (scale * cropW), (int) (scale * cropH), hints); lastRendering = rendered; } else { rendered = colorCorrected.createScaledRendering((int) (scale * cropW), (int) (scale * cropH), hints); lastRendering = rendered; } fireNewRenderingEvent(); return rendered; }