java.awt.Graphics2D.getRenderingHint()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(131)

本文整理了Java中java.awt.Graphics2D.getRenderingHint()方法的一些代码示例,展示了Graphics2D.getRenderingHint()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graphics2D.getRenderingHint()方法的具体详情如下:
包路径:java.awt.Graphics2D
类名称:Graphics2D
方法名:getRenderingHint

Graphics2D.getRenderingHint介绍

暂无

代码示例

代码示例来源:origin: org.apache.poi/poi

/**
 * Replace font families for Windows JVM 6, which contains a font rendering error.
 * This is likely to be removed, when POI upgrades to JDK 7
 *
 * @param graphics the graphics context which will contain the font mapping
 */
public void fixFonts(Graphics2D graphics) {
  if (!JvmBugs.hasLineBreakMeasurerBug()) return;
  @SuppressWarnings("unchecked")
  Map<String,String> fontMap = (Map<String,String>)graphics.getRenderingHint(Drawable.FONT_MAP);
  if (fontMap == null) {
    fontMap = new HashMap<>();
    graphics.setRenderingHint(Drawable.FONT_MAP, fontMap);
  }
  
  String fonts[][] = {
    { "Calibri", "Lucida Sans" },
    { "Cambria", "Lucida Bright" },
    { "Times New Roman", "Lucida Bright" },
    { "serif", "Lucida Bright" }
  };
  for (String f[] : fonts) {
    if (!fontMap.containsKey(f[0])) {
      fontMap.put(f[0], f[1]);
    }
  }
}

代码示例来源:origin: org.apache.poi/poi

/**
 * Returns the DrawFactory, preferably via a graphics instance.
 * If graphics is null, the current thread local is checked or
 * if it is not set, a new factory is created. 
 *
 * @param graphics the current graphics context or null
 * @return the draw factory
 */
public static DrawFactory getInstance(Graphics2D graphics) {
  // first try to find the factory over the rendering hint
  DrawFactory factory = null;
  boolean isHint = false;
  if (graphics != null) {
    factory = (DrawFactory)graphics.getRenderingHint(Drawable.DRAW_FACTORY);
    isHint = (factory != null);
  }
  // secondly try the thread local default
  if (factory == null) {
    factory = defaultFactory.get();
  }
  // and at last, use the default factory
  if (factory == null) {
    factory = new DrawFactory();
  }
  if (graphics != null && !isHint) {
    graphics.setRenderingHint(Drawable.DRAW_FACTORY, factory);
  }
  return factory;
}

代码示例来源:origin: chewiebug/GCViewer

/**
 * Adds version string below <code>logoImage</code>.
 *
 * @param g
 */
private void drawVersionString(Graphics g, ImageIcon logoImage) {
  g.setColor(Color.LIGHT_GRAY);
  g.setFont(new Font("Serif", Font.BOLD, 12));
  // use anti aliasing to draw string
  Graphics2D g2d = (Graphics2D)g;
  Object oldAAHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  String versionString = "version: " + BuildInfoReader.getVersion() + " (" + BuildInfoReader.getBuildDate() + ")";
  g.drawString(versionString,
      getWidth()/2 - g.getFontMetrics().stringWidth(versionString)/2,
      getHeight()/2 + logoImage.getIconHeight()/2 + 25);
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAAHint);
}

代码示例来源:origin: chewiebug/GCViewer

protected void paintComponent(Graphics g) {
  super.paintComponent(g);
  Graphics2D g2d = (Graphics2D)g;
  Paint oldPaint = g2d.getPaint();
  Object oldAAHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
  if (modelChart.isAntiAlias()) g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g2d.setPaint(getLinePaint());
  paintComponent(g2d);
  g2d.setPaint(oldPaint);
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAAHint);
}

代码示例来源:origin: org.apache.poi/poi

public void draw(Graphics2D graphics) {
  // the coordinate system of this group of shape
  Rectangle2D interior = getShape().getInteriorAnchor();
  // anchor of this group relative to the parent shape
  Rectangle2D exterior = getShape().getAnchor();
  AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);
  AffineTransform tx0 = new AffineTransform(tx);
  double scaleX = interior.getWidth() == 0. ? 1.0 : exterior.getWidth() / interior.getWidth();
  double scaleY = interior.getHeight() == 0. ? 1.0 : exterior.getHeight() / interior.getHeight();
  tx.translate(exterior.getX(), exterior.getY());
  tx.scale(scaleX, scaleY);
  tx.translate(-interior.getX(), -interior.getY());
  DrawFactory drawFact = DrawFactory.getInstance(graphics);
  AffineTransform at2 = graphics.getTransform();
  
  for (Shape<?,?> child : getShape()) {
    // remember the initial transform and restore it after we are done with the drawing
    AffineTransform at = graphics.getTransform();
    graphics.setRenderingHint(Drawable.GSAVE, true);
    Drawable draw = drawFact.getDrawable(child);
    draw.applyTransform(graphics);
    draw.draw(graphics);
    // restore the coordinate system
    graphics.setTransform(at);
    graphics.setRenderingHint(Drawable.GRESTORE, true);
  }
  graphics.setTransform(at2);
  graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, tx0);
}

代码示例来源:origin: sarxos/webcam-capture

assert g2 != null;
Object antialiasing = g2.getRenderingHint(KEY_ANTIALIASING);
g2.setRenderingHint(KEY_ANTIALIASING, isAntialiasingEnabled() ? VALUE_ANTIALIAS_ON : VALUE_ANTIALIAS_OFF);
g2.setBackground(Color.BLACK);
g2.fillRect(0, 0, getWidth(), getHeight());
g2.setRenderingHint(KEY_ANTIALIASING, antialiasing);

代码示例来源:origin: sarxos/webcam-capture

int ih = image.getHeight();
Object antialiasing = g2.getRenderingHint(KEY_ANTIALIASING);
Object rendering = g2.getRenderingHint(KEY_RENDERING);
g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_OFF);
g2.setRenderingHint(KEY_RENDERING, VALUE_RENDER_SPEED);
g2.setBackground(Color.BLACK);
g2.setColor(Color.BLACK);
      gr.setRenderingHint(hint.getKey(), hint.getValue());

代码示例来源:origin: org.apache.poi/poi

Map<String, CustomGeometry> presets = (graphics == null)
  ? null
  : (Map<String, CustomGeometry>)graphics.getRenderingHint(Drawable.PRESET_GEOMETRY_CACHE);
    graphics.setRenderingHint(Drawable.PRESET_GEOMETRY_CACHE, presets);

代码示例来源:origin: org.apache.poi/poi

AffineTransform txg = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);
AffineTransform tx = new AffineTransform();
try {
    tx.translate(-shapeBounds.getCenterX(), -shapeBounds.getCenterY());
  graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, tx);
  d.draw(graphics);
} finally {
  graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, txg);

代码示例来源:origin: chewiebug/GCViewer

/**
 * @see com.tagtraum.perf.gcviewer.view.ChartRenderer#paintComponent(java.awt.Graphics2D)
 */
public void paintComponent(Graphics2D g2d) {
  if ((!drawPolygon) && (!isDrawLine())) return;
  if (polygon == null) {
    // don't recompute polygon for each paint event
    polygon = computePolygon(getModelChart(), getModelChart().getModel());
  }
  clippedPolygon = initClippedPolygon(polygon, g2d.getClip());
  if (drawPolygon) {
    // don't antialias the polygon, if we are going to antialias the bounding lines
    Object oldAAHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    if (isDrawLine()) {
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    }
    g2d.setPaint(createPaint(polygon));
    g2d.fillPolygon(clippedPolygon);
    if (isDrawLine()) {
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAAHint);
    }
  }
  if (isDrawLine()) {
    g2d.setPaint(getLinePaint());
    g2d.drawPolyline(clippedPolygon.xpoints, clippedPolygon.ypoints, clippedPolygon.npoints-1);
  }
}

代码示例来源:origin: geotools/geotools

/** @see org.geotools.renderer.lite.LabelCache#end(java.awt.Graphics2D, java.awt.Rectangle) */
public void end(Graphics2D graphics, Rectangle displayArea) {
  final Object antialiasing = graphics.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
  final Object textAntialiasing =
      graphics.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
  try {
    // if we are asked to antialias only text but we're drawing using
    // the outline
    // method, we need to re-enable graphics antialiasing during label
    // painting
    if (labelRenderingMode != LabelRenderingMode.STRING
        && antialiasing == RenderingHints.VALUE_ANTIALIAS_OFF
        && textAntialiasing == RenderingHints.VALUE_TEXT_ANTIALIAS_ON) {
      graphics.setRenderingHint(
          RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }
    paintLabels(graphics, displayArea);
  } finally {
    if (antialiasing != null) {
      graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antialiasing);
    }
  }
}

代码示例来源:origin: geotools/geotools

public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform tmp = g2d.getTransform();
    Object oldInterpolation = g2d.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
    if (oldInterpolation == null) {
      oldInterpolation = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
    }
    try {
      AffineTransform at = new AffineTransform(tmp);
      at.concatenate(this.at);
      g2d.setTransform(at);
      g2d.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      icon.paintIcon(c, g2d, 0, 0);
    } finally {
      g2d.setTransform(tmp);
      g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, oldInterpolation);
    }
  }
}

代码示例来源:origin: geotools/geotools

public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform tmp = g2d.getTransform();
    Object oldInterpolation = g2d.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
    if (oldInterpolation == null) {
      oldInterpolation = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
    }
    try {
      AffineTransform at = new AffineTransform(tmp);
      at.translate(x, y);
      at.scale(scale, scale);
      g2d.setTransform(at);
      g2d.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      icon.paintIcon(c, g2d, 0, 0);
    } finally {
      g2d.setTransform(tmp);
      g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, oldInterpolation);
    }
  }
}

代码示例来源:origin: geotools/geotools

Object interpolation = graphics.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
if (interpolation == null) {
  interpolation = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
  graphics.setRenderingHint(
      RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  graphics.drawRenderedImage(image, markAT);
} finally {
  graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, interpolation);

代码示例来源:origin: knowm/XChart

Object oldHint = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldHint);

代码示例来源:origin: knowm/XChart

@Override
public void paint(Graphics2D g) {
 Object oldHint = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldHint);

代码示例来源:origin: geotools/geotools

Object oldInterpolationValue = g2d.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
if (randomRotation && icon != null) {
  g2d.setRenderingHint(
      RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  g2d.setTransform(originalTransform);
  if (oldInterpolationValue != null) {
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, oldInterpolationValue);

代码示例来源:origin: knowm/XChart

double starty = yOffset + chart.getStyler().getLegendPadding();
Object oldHint = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldHint);

代码示例来源:origin: knowm/XChart

double starty = yOffset + chart.getStyler().getLegendPadding();
Object oldHint = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldHint);

代码示例来源:origin: knowm/XChart

double starty = yOffset + chart.getStyler().getLegendPadding();
Object oldHint = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldHint);

相关文章

Graphics2D类方法