java.awt.RenderingHints Java Examples
The following examples show how to use
java.awt.RenderingHints.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: pumpernickel Author: mickleness File: ScalingDemo.java License: MIT License | 6 votes |
@Override public BufferedImage call() throws Exception { BufferedImage bi = new BufferedImage(80, 60, BufferedImage.TYPE_INT_RGB); Graphics2D g = bi.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.transform(TransformUtils.createAffineTransform(new Dimension( sampleImage.getWidth(), sampleImage.getHeight()), new Dimension(bi.getWidth(), bi.getHeight()))); g.drawImage(sampleImage, 0, 0, null); g.dispose(); return bi; }
Example #2
Source Project: stendhal Author: arianne File: Blend.java License: GNU General Public License v2.0 | 6 votes |
@Override public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints arg2) { switch (mode) { case MULTIPLY: return new MultiplyContext(); // Modes with significant creation overhead (lookup tables). Cache those case SOFT_LIGHT: CompositeContext ctx = cache.get(Mode.SOFT_LIGHT); if (ctx == null) { ctx = new BlendContext(mode, color); cache.put(Mode.SOFT_LIGHT, ctx); } return ctx; default: return new BlendContext(mode, color); } }
Example #3
Source Project: tuxguitar Author: phiresky File: AWTPainter.java License: GNU Lesser General Public License v2.1 | 6 votes |
public void closePath(){ if(this.pathEmpty){ System.out.println("Warning: Empty Path!"); } if( (this.style & PATH_DRAW) != 0){ this.gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); this.gc.setColor(this.foreground.getHandle(this.alpha)); this.gc.draw(this.path); } if( (this.style & PATH_FILL) != 0){ this.gc.setColor(this.background.getHandle(this.alpha)); this.gc.fill(this.path); } this.style = 0; this.path = null; this.pathEmpty = true; this.setAntialias( false ); }
Example #4
Source Project: pumpernickel Author: mickleness File: AddRulesTest.java License: MIT License | 6 votes |
private void reportFailure(String id, Shape good, Shape bad) { Rectangle2D r = good.getBounds2D(); r.add(bad.getBounds2D()); BufferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); g.transform(RectangularTransform.create(r, new Rectangle(0, 0, image.getWidth(), image.getHeight()))); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.blue); g.fill(good); g.setColor(new Color(255, 0, 0, 128)); g.fill(bad); g.dispose(); printStream.println("the resulting shape for \"" + id + "\" wasn't correct."); try { ImageIO.write(image, "png", new File("comparison " + (ctr++) + ".png")); } catch (IOException e) { e.printStackTrace(); } }
Example #5
Source Project: CodenameOne Author: codenameone File: FontTask.java License: GNU General Public License v2.0 | 6 votes |
@Override public void addToResources(EditableResources e) { if(logicalName == null) { logicalName = "Arial" + getIdentity() + size; createBitmap = false; } else { if(logicalName.indexOf('-') < 0) { logicalName += getIdentity() + size; } } Object aa; if(antiAliasing) { aa = RenderingHints.VALUE_TEXT_ANTIALIAS_ON; } else { aa = RenderingHints.VALUE_TEXT_ANTIALIAS_OFF; } EditorFont f = new EditorFont(Font.createSystemFont(systemFace, systemStyle, systemSize), null, logicalName, createBitmap, aa, charset); e.setFont(getName(), f); }
Example #6
Source Project: pentaho-reporting Author: pentaho File: PdfGraphics2D.java License: GNU Lesser General Public License v2.1 | 6 votes |
/** * Constructor for PDFGraphics2D. */ public PdfGraphics2D( final PdfContentByte cb, final float width, final float height, final PdfOutputProcessorMetaData metaData ) { this.metaData = metaData; dg2.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON ); setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON ); this.transform = new AffineTransform(); paint = Color.black; background = Color.white; setFont( new Font( "sanserif", Font.PLAIN, 12 ) ); this.cb = cb; cb.saveState(); this.width = width; this.height = height; clip = new Area( new Rectangle2D.Float( 0, 0, width, height ) ); clip( clip ); oldStroke = strokeOne; stroke = strokeOne; originalStroke = strokeOne; setStrokeDiff( stroke, null ); cb.saveState(); }
Example #7
Source Project: Ardulink-1 Author: Ardulink File: SimplePositionListener.java License: Apache License 2.0 | 6 votes |
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.RED); int x = 0; int y = 0; Dimension dimension = getSize(); int dim = Math.min(dimension.width, dimension.height) / 2; if(position != null) { x = position.x * dim / maxSize; y = position.y * dim / maxSize; } g2.fillOval((dimension.width / 2) + x - (POINT_DIM / 2), (dimension.height / 2) - y - (POINT_DIM / 2), POINT_DIM, POINT_DIM); // g2.drawRect(0, 0, dimension.width - 1, dimension.height - 1); }
Example #8
Source Project: astor Author: SpoonLabs File: LowDiscrepancyGeneratorComparison.java License: GNU General Public License v2.0 | 6 votes |
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = getWidth(); int h = getHeight(); g2.clearRect(0, 0, w, h); g2.setPaint(Color.black); g2.drawRect(0, 0, w - 1, h - 1); for (Vector2D point : points) { Vector2D p = transform(point, w, h); double[] arr = p.toArray(); g2.draw(new Rectangle2D.Double(arr[0] - 1, arr[1] - 1, 2, 2)); } }
Example #9
Source Project: coming Author: SpoonLabs File: JGenProg2015_000_s.java License: MIT License | 6 votes |
/** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.borderStroke = SerialUtilities.readStroke(stream); this.borderPaint = SerialUtilities.readPaint(stream); this.backgroundPaint = SerialUtilities.readPaint(stream); this.progressListeners = new EventListenerList(); this.changeListeners = new EventListenerList(); this.renderingHints = new RenderingHints( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // register as a listener with sub-components... if (this.title != null) { this.title.addChangeListener(this); } for (int i = 0; i < getSubtitleCount(); i++) { getSubtitle(i).addChangeListener(this); } this.plot.addChangeListener(this); }
Example #10
Source Project: jdk8u_jdk Author: JetBrains File: DrawRotatedString.java License: GNU General Public License v2.0 | 6 votes |
private static BufferedImage createBufferedImage(final boolean aa) { final BufferedImage bi = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_RGB); final Graphics2D bg = bi.createGraphics(); bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aa ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); bg.setColor(Color.RED); bg.fillRect(0, 0, SIZE, SIZE); bg.translate(100, 100); bg.rotate(Math.toRadians(90)); bg.setColor(Color.BLACK); bg.setFont(bg.getFont().deriveFont(20.0f)); bg.drawString("MMMMMMMMMMMMMMMM", 0, 0); bg.dispose(); return bi; }
Example #11
Source Project: pumpernickel Author: mickleness File: ImageContext.java License: MIT License | 6 votes |
/** * Return the interpolation rendering hint to use. This will not return * null. If this is undefined, then the antialiasing and rendering hints are * consulted (which will return either NEAREST_NEIGHBOR or BILINEAR). If * nothing is defined then this returns BILINEAR. */ protected Object getInterpolationRenderingHint() { Object v = renderingHints.get(RenderingHints.KEY_INTERPOLATION); if (v != null) return v; v = renderingHints.get(RenderingHints.KEY_ANTIALIASING); if (RenderingHints.VALUE_ANTIALIAS_ON.equals(v)) { return RenderingHints.VALUE_INTERPOLATION_BILINEAR; } else if (RenderingHints.VALUE_ANTIALIAS_OFF.equals(v)) { return RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; } v = renderingHints.get(RenderingHints.KEY_RENDERING); if (RenderingHints.VALUE_RENDER_QUALITY.equals(v)) { return RenderingHints.VALUE_INTERPOLATION_BILINEAR; } else if (RenderingHints.VALUE_RENDER_SPEED.equals(v)) { return RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; } // nothing is defined: return RenderingHints.VALUE_INTERPOLATION_BILINEAR; }
Example #12
Source Project: openjdk-jdk8u-backup Author: AdoptOpenJDK File: TSFrame.java License: GNU General Public License v2.0 | 6 votes |
private static void render(Graphics g, int w, int h, boolean useNonOpaque) { if (useNonOpaque) { Graphics2D g2d = (Graphics2D)g; GradientPaint p = new GradientPaint(0.0f, 0.0f, new Color(rnd.nextInt(0xffffff)), w, h, new Color(rnd.nextInt(0xff), rnd.nextInt(0xff), rnd.nextInt(0xff), 0), true); g2d.setPaint(p); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.fillOval(0, 0, w, h); } else { g.setColor(new Color(rnd.nextInt(0xffffff))); g.fillRect(0, 0, w, h); } }
Example #13
Source Project: android-classyshark Author: google File: RingChart.java License: Apache License 2.0 | 6 votes |
public void render(int width, int height, ClassNode rootNode, Graphics g) { image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D imageG2d = (Graphics2D)image.getGraphics(); imageG2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); imageG2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); imageG2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); imageG2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); imageG2d.setComposite(AlphaComposite.Src); imageG2d.setColor(GuiMode.getTheme().getBackgroundColor()); imageG2d.fillRect(0, 0, width, height); int graphWidth = width - MARGIN * 2; int graphHeight = height - MARGIN * 2; imageG2d.translate(MARGIN, MARGIN); int size = Math.min(graphWidth, graphHeight); renderNode(graphWidth, graphHeight, size, 0, 360, rootNode, imageG2d, 1, PALETTE); imageG2d.dispose(); g.drawImage(image, 0, 0, null); g.dispose(); }
Example #14
Source Project: jdk8u_jdk Author: JetBrains File: ColorConvertOp.java License: GNU General Public License v2.0 | 6 votes |
/** * Constructs a new ColorConvertOp from a ColorSpace object. * The RenderingHints argument may be null. This * Op can be used only with BufferedImages, and is primarily useful * when the {@link #filter(BufferedImage, BufferedImage) filter} * method is invoked with a destination argument of null. * In that case, the ColorSpace defines the destination color space * for the destination created by the filter method. Otherwise, the * ColorSpace defines an intermediate space to which the source is * converted before being converted to the destination space. * @param cspace defines the destination <code>ColorSpace</code> or an * intermediate <code>ColorSpace</code> * @param hints the <code>RenderingHints</code> object used to control * the color conversion, or <code>null</code> * @throws NullPointerException if cspace is null */ public ColorConvertOp (ColorSpace cspace, RenderingHints hints) { if (cspace == null) { throw new NullPointerException("ColorSpace cannot be null"); } if (cspace instanceof ICC_ColorSpace) { profileList = new ICC_Profile [1]; /* 1 profile in the list */ profileList [0] = ((ICC_ColorSpace) cspace).getProfile(); } else { CSList = new ColorSpace[1]; /* non-ICC case: 1 ColorSpace in list */ CSList[0] = cspace; } this.hints = hints; }
Example #15
Source Project: buffer_bci Author: jadref File: FastScatterPlot.java License: GNU General Public License v3.0 | 6 votes |
/** * Draws the gridlines for the plot, if they are visible. * * @param g2 the graphics device. * @param dataArea the data area. * @param ticks the ticks. */ protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) { if (!isDomainGridlinesVisible()) { return; } Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL); g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); Iterator iterator = ticks.iterator(); while (iterator.hasNext()) { ValueTick tick = (ValueTick) iterator.next(); double v = this.domainAxis.valueToJava2D(tick.getValue(), dataArea, RectangleEdge.BOTTOM); Line2D line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); g2.setPaint(getDomainGridlinePaint()); g2.setStroke(getDomainGridlineStroke()); g2.draw(line); } g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved); }
Example #16
Source Project: openjdk-jdk9 Author: AdoptOpenJDK File: HelvLtOblTest.java License: GNU General Public License v2.0 | 6 votes |
BufferedImage drawText(boolean doGV) { int w = 400; int h = 50; BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g = bi.createGraphics(); g.setColor(Color.white); g.fillRect(0,0,w,h); g.setColor(Color.black); Font f = helvFont.deriveFont(Font.PLAIN, 40); g.setFont(f); int x = 5; int y = h - 10; if (doGV) { FontRenderContext frc = new FontRenderContext(null, true, true); GlyphVector gv = f.createGlyphVector(frc, codes); g.drawGlyphVector(gv, 5, y); } else { g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); g.drawString(str, x, y); } return bi; }
Example #17
Source Project: commons-imaging Author: apache File: ColorTools.java License: Apache License 2.0 | 6 votes |
public BufferedImage convertToColorSpace(final BufferedImage bi, final ColorSpace to) { final ColorSpace from = bi.getColorModel().getColorSpace(); final RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); hints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); hints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); final ColorConvertOp op = new ColorConvertOp(from, to, hints); BufferedImage result = op.filter(bi, null); result = relabelColorSpace(result, to); return result; }
Example #18
Source Project: Azzet Author: ClickerMonkey File: TestApplet.java License: Open Software License 3.0 | 6 votes |
public synchronized void paint(Graphics g) { long time = System.nanoTime(); update( (time - currentTime) * 0.000000001f ); currentTime = time; BufferedImage buffer = getBuffer(); Graphics2D gr = buffer.createGraphics(); gr.setColor( getBackground() ); gr.clearRect( 0, 0, buffer.getWidth(), buffer.getHeight() ); gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); draw( gr ); g.drawImage( buffer, 0, 0, this ); }
Example #19
Source Project: mars-sim Author: mars-sim File: EllipticGradientPaint.java License: GNU General Public License v3.0 | 5 votes |
@Override public java.awt.PaintContext createContext(final ColorModel COLOR_MODEL, final Rectangle DEVICE_BOUNDS, final Rectangle2D USER_BOUNDS, final AffineTransform TRANSFORM, final RenderingHints RENDERING_HINTS) { final Point2D TRANSFORMED_CENTER = TRANSFORM.transform(CENTER, null); final Point2D TRANSFORMED_RADIUS_XY = TRANSFORM.deltaTransform(RADIUS_X_Y, null); return new OvalGradientContext(TRANSFORMED_CENTER, TRANSFORMED_RADIUS_XY, FRACTIONS, COLORS); }
Example #20
Source Project: freecol Author: FreeCol File: ImageLibrary.java License: GNU General Public License v2.0 | 5 votes |
public static BufferedImage createResizedImage(Image image, int width, int height) { BufferedImage scaled = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = scaled.createGraphics(); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g.drawImage(image, 0, 0, width, height, null); g.dispose(); return scaled; }
Example #21
Source Project: FlatLaf Author: JFormDesigner File: FlatLaf.java License: Apache License 2.0 | 5 votes |
private void putAATextInfo( UIDefaults defaults ) { if( SystemInfo.IS_JAVA_9_OR_LATER ) { Object desktopHints = Toolkit.getDefaultToolkit().getDesktopProperty( DESKTOPFONTHINTS ); if( desktopHints instanceof Map ) { @SuppressWarnings( "unchecked" ) Map<Object, Object> hints = (Map<Object, Object>) desktopHints; Object aaHint = hints.get( RenderingHints.KEY_TEXT_ANTIALIASING ); if( aaHint != null && aaHint != RenderingHints.VALUE_TEXT_ANTIALIAS_OFF && aaHint != RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT ) { defaults.put( RenderingHints.KEY_TEXT_ANTIALIASING, aaHint ); defaults.put( RenderingHints.KEY_TEXT_LCD_CONTRAST, hints.get( RenderingHints.KEY_TEXT_LCD_CONTRAST ) ); } } } else { // Java 8 try { Object key = Class.forName( "sun.swing.SwingUtilities2" ) .getField( "AA_TEXT_PROPERTY_KEY" ) .get( null ); Object value = Class.forName( "sun.swing.SwingUtilities2$AATextInfo" ) .getMethod( "getAATextInfo", boolean.class ) .invoke( null, true ); defaults.put( key, value ); } catch( Exception ex ) { Logger.getLogger( FlatLaf.class.getName() ).log( Level.SEVERE, null, ex ); throw new RuntimeException( ex ); } } }
Example #22
Source Project: pumpernickel Author: mickleness File: IntersectionsTest.java License: MIT License | 5 votes |
public static final void draw(Shape shape, AffineTransform at, BufferedImage bi, boolean showControlPoints) { clear(bi); Graphics2D g = bi.createGraphics(); g.setColor(Color.black); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.fill(new BasicStroke(1).createStrokedShape(at .createTransformedShape(shape))); if (showControlPoints) { PathIterator i; double[] coords = new double[6]; i = shape.getPathIterator(at); while (i.isDone() == false) { int k = i.currentSegment(coords); if (k == PathIterator.SEG_QUADTO || k == PathIterator.SEG_CUBICTO) { g.setColor(Color.blue); g.fill(new Rectangle2D.Double(coords[0] - 1, coords[1] - 1, 2, 2)); } if (k == PathIterator.SEG_CUBICTO) { g.setColor(Color.green); g.fill(new Rectangle2D.Double(coords[2] - 1, coords[3] - 1, 2, 2)); } i.next(); } } g.dispose(); }
Example #23
Source Project: magarena Author: magarena File: ZoneToggleButton.java License: GNU General Public License v3.0 | 5 votes |
private void drawSelectedRoundBorder(Graphics g, Color aColor) { final Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setStroke(DEFAULT_BORDER_STROKE); g2d.setColor(aColor); g2d.drawRoundRect(1, 1, getWidth()-3, getHeight()-3, 16, 16); }
Example #24
Source Project: openstock Author: lcmeyer37 File: AbstractXYItemRenderer.java License: GNU General Public License v3.0 | 5 votes |
/** * Draws a line perpendicular to the domain axis. * * @param g2 the graphics device. * @param plot the plot. * @param axis the value axis. * @param dataArea the area for plotting data (not yet adjusted for any 3D * effect). * @param value the value at which the grid line should be drawn. * @param paint the paint (<code>null</code> not permitted). * @param stroke the stroke (<code>null</code> not permitted). * * @since 1.0.5 */ public void drawDomainLine(Graphics2D g2, XYPlot plot, ValueAxis axis, Rectangle2D dataArea, double value, Paint paint, Stroke stroke) { Range range = axis.getRange(); if (!range.contains(value)) { return; } PlotOrientation orientation = plot.getOrientation(); Line2D line = null; double v = axis.valueToJava2D(value, dataArea, plot.getDomainAxisEdge()); if (orientation.isHorizontal()) { line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); } else if (orientation.isVertical()) { line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); } g2.setPaint(paint); g2.setStroke(stroke); Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL); g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); g2.draw(line); g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved); }
Example #25
Source Project: sambox Author: torakiki File: PDImageXObject.java License: Apache License 2.0 | 5 votes |
/** * High-quality image scaling. */ private BufferedImage scaleImage(BufferedImage image, int width, int height) { BufferedImage image2 = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = image2.createGraphics(); if (getInterpolate()) { g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); } g.drawImage(image, 0, 0, width, height, 0, 0, image.getWidth(), image.getHeight(), null); g.dispose(); return image2; }
Example #26
Source Project: Logisim Author: LogisimIt File: HorizontalSplitPane.java License: GNU General Public License v3.0 | 5 votes |
@Override public void paintComponent(Graphics g) { if (AppPreferences.ANTI_ALIASING.getBoolean()) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } if (dragging) { g.setColor(DRAG_COLOR); g.fillRect(0, 0, getWidth(), getHeight()); } }
Example #27
Source Project: jdk8u-jdk Author: lambdalab-mirror File: TestTransform.java License: GNU General Public License v2.0 | 5 votes |
public static void testFontOfSize(float sz, Object textHint) { BufferedImage bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = (Graphics2D) bi.getGraphics(); g2.setFont(g2.getFont().deriveFont(sz)); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, textHint); g2.drawString("test", 100, 100); }
Example #28
Source Project: TencentKona-8 Author: Tencent File: IncorrectAlphaConversionBicubic.java License: GNU General Public License v2.0 | 5 votes |
public static void main(final String[] args) { final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); final GraphicsDevice gd = ge.getDefaultScreenDevice(); final GraphicsConfiguration gc = gd.getDefaultConfiguration(); final VolatileImage vi = gc.createCompatibleVolatileImage(SIZE, SIZE, TRANSLUCENT); final BufferedImage bi = makeUnmanagedBI(gc, TRANSLUCENT); final int expected = bi.getRGB(2, 2); int attempt = 0; BufferedImage snapshot; while (true) { if (++attempt > 10) { throw new RuntimeException("Too many attempts: " + attempt); } vi.validate(gc); final Graphics2D g2d = vi.createGraphics(); g2d.setComposite(AlphaComposite.Src); g2d.scale(2, 2); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2d.drawImage(bi, 0, 0, null); g2d.dispose(); snapshot = vi.getSnapshot(); if (vi.contentsLost()) { continue; } break; } final int actual = snapshot.getRGB(2, 2); if (actual != expected) { System.err.println("Actual: " + Integer.toHexString(actual)); System.err.println("Expected: " + Integer.toHexString(expected)); throw new RuntimeException("Test failed"); } }
Example #29
Source Project: pumpernickel Author: mickleness File: MultiThumbSliderUI.java License: MIT License | 5 votes |
@Override public void paint(Graphics g, JComponent slider2) { if (slider2 != slider) throw new RuntimeException( "only use this UI on the GradientSlider it was constructed with"); Graphics2D g2 = (Graphics2D) g; int w = slider.getWidth(); int h = slider.getHeight(); if (slider.isOpaque()) { g.setColor(slider.getBackground()); g.fillRect(0, 0, w, h); } if (slider2.hasFocus()) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); paintFocus(g2); } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); paintTrack(g2); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); paintThumbs(g2); }
Example #30
Source Project: magarena Author: magarena File: AnnotatedCardPanel.java License: GNU General Public License v3.0 | 5 votes |
private void drawIcons(final Graphics2D g2d) { if (!cardIcons.isEmpty()) { final int BORDER_WIDTH = 2; final BasicStroke BORDER_STROKE = new BasicStroke(BORDER_WIDTH); final Stroke defaultStroke = g2d.getStroke(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // draw icons int y = 10; int x = 0; final int ICON_WIDTH = 36; final int ICON_HEIGHT = 32; final int CORNER_ARC = 16; final GradientPaint PAINT_COLOR = new GradientPaint(0, 0, GRADIENT_FROM_COLOR, ICON_WIDTH, 0, GRADIENT_TO_COLOR); iconShapes.clear(); for (CardIcon cardIcon : cardIcons) { // icon bounds should be relative to CardPopupPanel. final Rectangle2D iconShapeRect = new Rectangle2D.Double((double)x, (double)y, (double)ICON_WIDTH, 32d); iconShapes.add(iconShapeRect); // final Rectangle rect = new Rectangle(x, y, ICON_WIDTH, ICON_HEIGHT); g2d.setPaint(PAINT_COLOR); g2d.fillRoundRect(rect.x, rect.y, rect.width, rect.height, CORNER_ARC, CORNER_ARC); g2d.setPaint(Color.BLACK); g2d.setStroke(BORDER_STROKE); g2d.drawRoundRect(rect.x, rect.y, rect.width, rect.height, CORNER_ARC, CORNER_ARC); g2d.setStroke(defaultStroke); // final ImageIcon icon = cardIcon.getIcon(); final int iconOffsetX = (ICON_WIDTH / 2) - (icon.getIconWidth() / 2); final int iconOffsetY = 16 - (icon.getIconHeight() / 2); icon.paintIcon(this, g2d, x + iconOffsetX, y + iconOffsetY); y += ICON_HEIGHT + 1; } } }