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

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

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

Graphics2D.getColor介绍

暂无

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

public void switchForegroundBackgroundColors() {
 Color fg = gc.getColor();
 Color bg = gc.getBackground();
 gc.setColor( bg );
 gc.setBackground( fg );
}

代码示例来源:origin: pentaho/pentaho-kettle

public void switchForegroundBackgroundColors() {
 Color fg = gc.getColor();
 Color bg = gc.getBackground();
 gc.setColor( bg );
 gc.setBackground( fg );
}

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

public void makeTransparent(Graphics2D g2) {
  Color col = g2.getColor();
  Composite comp = null;
  // force transparence of this layer only. If no buffering we would clear layers below
  if (buffering) {
    comp = g2.getComposite();
    g2.setComposite(AlphaComposite.Clear);
  }
  g2.setColor(new Color(0, 0, 0, 0));
  g2.fillRect(0, 0, bounds.width, bounds.height);
  g2.setColor(col);
  if (comp != null) {
    g2.setComposite(comp);
  }
}

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

public void plotNode(Graphics2D g2, NodeAccess na, int loc, Color c, int size, String text) {
  double lat = na.getLatitude(loc);
  double lon = na.getLongitude(loc);
  if (lat < bounds.minLat || lat > bounds.maxLat || lon < bounds.minLon || lon > bounds.maxLon) {
    return;
  }
  Color old = g2.getColor();
  g2.setColor(c);
  plot(g2, lat, lon, size);
  g2.setColor(old);
}

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

public void processFlash(final Graphics2D graphics)
{
  if (flashStart == null)
  {
    return;
  }
  if (client.getGameCycle() % 40 >= 20)
  {
    return;
  }
  final Color color = graphics.getColor();
  graphics.setColor(FLASH_COLOR);
  graphics.fill(new Rectangle(client.getCanvas().getSize()));
  graphics.setColor(color);
  if (Instant.now().minusMillis(FLASH_DURATION).isAfter(flashStart))
  {
    flashStart = null;
  }
}

代码示例来源:origin: stanfordnlp/CoreNLP

Color curColor = g2.getColor();
g2.setColor(paintColor);
g2.drawString(nodeStr, (float) (nodeTab + start.getX()), (float) (start.getY() + nodeAscent));
g2.setColor(curColor);
double layerMultiplier = (1.0 + belowLineSkip + aboveLineSkip + parentSkip);
double layerHeight = nodeHeight * layerMultiplier;

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

if (ga instanceof TextAttributes) {
  final TextAttributes ta = (TextAttributes) ga;
  final Color currentColor = _graphics.getColor();
  Color fontColor = ta.getTextColor();
  if (fontColor == null) {
    fontColor = _defaultColor;
  _graphics.setColor(fontColor);
  _graphics.setColor(currentColor);

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

-SNAP_CORNER_SIZE.height);
final Color previous = graphics.getColor();
  graphics.setColor(corner.contains(mousePosition) ? SNAP_CORNER_ACTIVE_COLOR : SNAP_CORNER_COLOR);
  graphics.fill(corner);
graphics.setColor(previous);
    final Color previous = graphics.getColor();
    graphics.setColor(movedOverlay == overlay ? MOVING_OVERLAY_ACTIVE_COLOR : MOVING_OVERLAY_COLOR);
    graphics.draw(bounds);
    graphics.setColor(previous);

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

public static void drawShadowText(Graphics2D g2, String s, int x, int y, Color shadowColor, int offset) {
  g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  Color c = g2.getColor();
  g2.setColor(shadowColor);
  g2.drawString(s, x, y + offset);
  g2.setColor(c);
  g2.drawString(s, x, y);
}

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

protected BufferedImage getStartImage(int imageType, int width, int height) {
  if (imageType == BufferedImage.TYPE_CUSTOM) imageType = BufferedImage.TYPE_3BYTE_BGR;
  BufferedImage image = new BufferedImage(width, height, imageType);
  // white background
  Graphics2D g2D = (Graphics2D) image.getGraphics();
  Color save = g2D.getColor();
  g2D.setColor(Color.WHITE);
  g2D.fillRect(0, 0, image.getWidth(), image.getHeight());
  g2D.setColor(save);
  return image;
}

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

private BufferedImage getStartImage(int imageType) {
  Dimension dim = getStartDimension();
  if (imageType == BufferedImage.TYPE_CUSTOM)
    imageType = ImageMosaicJDBCReader.DEFAULT_IMAGE_TYPE;
  BufferedImage image =
      new BufferedImage((int) dim.getWidth(), (int) dim.getHeight(), imageType);
  Graphics2D g2D = (Graphics2D) image.getGraphics();
  Color save = g2D.getColor();
  g2D.setColor(backgroundColor);
  g2D.fillRect(0, 0, image.getWidth(), image.getHeight());
  g2D.setColor(save);
  return image;
}

代码示例来源:origin: magefree/mage

public static void drawRoundedBox(Graphics2D g, int x, int y, int w, int h, int bevel, Paint border, Paint fill) {
  g.setColor(new Color(0, 0, 0, 150));
  g.drawOval(x - 1, y - 1, bevel * 2, h);
  g.setPaint(border);
  g.drawOval(x, y, bevel * 2 - 1, h - 1);
  g.drawOval(x + w - bevel * 2, y, bevel * 2 - 1, h - 1);
  g.drawOval(x + 1, y + 1, bevel * 2 - 3, h - 3);
  g.drawOval(x + 1 + w - bevel * 2, y + 1, bevel * 2 - 3, h - 3);
  g.drawRect(x + bevel, y, w - 2 * bevel, h - 1);
  g.drawRect(x + 1 + bevel, y + 1, w - 2 * bevel - 2, h - 3);
  g.setPaint(fill);
  g.fillOval(x + 2, y + 2, bevel * 2 - 4, h - 4);
  g.fillOval(x + 2 + w - bevel * 2, y + 2, bevel * 2 - 4, h - 4);
  g.fillRect(x + bevel, y + 2, w - 2 * bevel, h - 4);
  g.setPaint(fill);
  g.setColor(abitbrighter(g.getColor()));
  g.drawLine(x + 1 + bevel, y + 1, x + 1 + bevel + w - 2 * bevel - 2, y + 1);
  g.setPaint(fill);
  g.setColor(abitdarker(g.getColor()));
  g.drawLine(x + 1 + bevel, y + h - 2, x + 1 + bevel + w - 2 * bevel - 2, y + h - 2);
}

代码示例来源:origin: magefree/mage

public static void drawZendikarLandBox(Graphics2D g, int x, int y, int w, int h, int bevel, Paint border, Paint fill) {
  g.setColor(new Color(0, 0, 0, 150));
  g.drawOval(x - 1, y, bevel * 2, h);
  g.setPaint(border);
  g.drawOval(x, y, bevel * 2 - 1, h - 1);
  g.drawOval(x + w - bevel * 2, y, bevel * 2 - 1, h - 1);
  g.drawOval(x + 1, y + 1, bevel * 2 - 3, h - 3);
  g.drawOval(x + 1 + w - bevel * 2, y + 1, bevel * 2 - 3, h - 3);
  // The big circle in the middle.. (diameter=2+1/4 of height) - 3/4 above line, 1/2 below  0.75 + .5 + 1= 2.25 = 9/4
  g.drawOval(x + w / 2 - h - h / 8, y - 3 * h / 4, 9 * h / 4, 9 * h / 4);
  g.drawRect(x + bevel, y, w - 2 * bevel, h - 1);
  g.drawRect(x + 1 + bevel, y + 1, w - 2 * bevel - 2, h - 3);
  g.setPaint(fill);
  g.setColor(abitbrighter(g.getColor()));
  g.drawLine(x + 1 + bevel, y + 1, x + 1 + bevel + w - 2 * bevel - 2, y + 1);
  g.setPaint(fill);
  g.setColor(abitdarker(g.getColor()));
  g.drawLine(x + 1 + bevel, y + h - 2, x + 1 + bevel + w - 2 * bevel - 2, y + h - 2);
  g.fillOval(x + 2, y + 2, bevel * 2 - 4, h - 4);
  g.fillOval(x + 2 + w - bevel * 2, y + 2, bevel * 2 - 4, h - 4);
  g.fillRect(x + bevel, y + 2, w - 2 * bevel, h - 4);
  g.fillOval(x + w / 2 - h - h / 8, y - 3 * h / 4, 9 * h / 4, 9 * h / 4);
}

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

public void draw(Graphics2D g) {
  if (getPointCount() < 2) return;
  // Since a contour has no fill or stroke information, draw it in black.
  // We save the current color so as not to disrupt the context.
  java.awt.Color savedColor = g.getColor();
  Stroke savedStroke = g.getStroke();
  GeneralPath gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, getPointCount());
  _extendPath(gp);
  g.setColor(java.awt.Color.BLACK);
  g.setStroke(DEFAULT_STROKE);
  g.draw(gp);
  g.setColor(savedColor);
  g.setStroke(savedStroke);
}

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

/**
 * @param width
 * @param height
 * @param backgroundColor
 * @param outputTransparentColor
 * @return BufferdImage filled with outputTransparentColor
 */
private BufferedImage getEmptyImage(
    int width, int height, Color backGroundcolor, Color outputTransparentColor) {
  BufferedImage emptyImage = new BufferedImage(width, height, DEFAULT_IMAGE_TYPE);
  Graphics2D g2D = (Graphics2D) emptyImage.getGraphics();
  Color save = g2D.getColor();
  g2D.setColor(backGroundcolor);
  g2D.fillRect(0, 0, emptyImage.getWidth(), emptyImage.getHeight());
  g2D.setColor(save);
  if (outputTransparentColor != null)
    emptyImage =
        new RenderedImageAdapter(
                ImageUtilities.maskColor(outputTransparentColor, emptyImage))
            .getAsBufferedImage();
  return emptyImage;
}

代码示例来源:origin: apache/pdfbox

/**
 * Glyph bounding boxes.
 */
@Override
protected void showGlyph(Matrix textRenderingMatrix, PDFont font, int code, String unicode,
             Vector displacement) throws IOException
{
  // draw glyph
  super.showGlyph(textRenderingMatrix, font, code, unicode, displacement);
  
  // bbox in EM -> user units
  Shape bbox = new Rectangle2D.Float(0, 0, font.getWidth(code) / 1000, 1);
  AffineTransform at = textRenderingMatrix.createAffineTransform();
  bbox = at.createTransformedShape(bbox);
  
  // save
  Graphics2D graphics = getGraphics();
  Color color = graphics.getColor();
  Stroke stroke = graphics.getStroke();
  Shape clip = graphics.getClip();
  // draw
  graphics.setClip(graphics.getDeviceConfiguration().getBounds());
  graphics.setColor(Color.RED);
  graphics.setStroke(new BasicStroke(.5f));
  graphics.draw(bbox);
  // restore
  graphics.setStroke(stroke);
  graphics.setColor(color);
  graphics.setClip(clip);
}

代码示例来源:origin: apache/pdfbox

/**
 * Filled path bounding boxes.
 */
@Override
public void fillPath(int windingRule) throws IOException
{
  // bbox in user units
  Shape bbox = getLinePath().getBounds2D();
  
  // draw path (note that getLinePath() is now reset)
  super.fillPath(windingRule);
  
  // save
  Graphics2D graphics = getGraphics();
  Color color = graphics.getColor();
  Stroke stroke = graphics.getStroke();
  Shape clip = graphics.getClip();
  // draw
  graphics.setClip(graphics.getDeviceConfiguration().getBounds());
  graphics.setColor(Color.GREEN);
  graphics.setStroke(new BasicStroke(.5f));
  graphics.draw(bbox);
  // restore
  graphics.setStroke(stroke);
  graphics.setColor(color);
  graphics.setClip(clip);
}

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

protected BufferedImage getStartImage(BufferedImage copyFrom, int width, int height) {
  Map<String, Object> properties = null;
  if (copyFrom.getPropertyNames() != null) {
    properties = new HashMap<String, Object>();
    for (String name : copyFrom.getPropertyNames()) {
      properties.put(name, copyFrom.getProperty(name));
    }
  }
  SampleModel sm = copyFrom.getSampleModel().createCompatibleSampleModel(width, height);
  WritableRaster raster = Raster.createWritableRaster(sm, null);
  BufferedImage image =
      new BufferedImage(
          copyFrom.getColorModel(),
          raster,
          copyFrom.isAlphaPremultiplied(),
          (Hashtable<?, ?>) properties);
  // white background
  Graphics2D g2D = (Graphics2D) image.getGraphics();
  Color save = g2D.getColor();
  g2D.setColor(Color.WHITE);
  g2D.fillRect(0, 0, image.getWidth(), image.getHeight());
  g2D.setColor(save);
  return image;
}

代码示例来源:origin: fossasia/neurolab-desktop

visGraphics.setColor(Color.WHITE);
visGraphics.fillRect(0, 0, width, visHeight + 40);
visGraphics.setColor(Color.BLACK);
  curOffset = displayRange * c + halfMin;
  visGraphics.setColor(new Color(230, 255, 255));
  visGraphics.fillRect(0, curOffset, samplesPerSecond, displayRange);
  visGraphics.setColor(Color.BLACK);
          visGraphics.setColor(visGraphics.getColor().brighter().brighter());

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

Color previousColor = graphics.getColor();
try {
  if (color != null) {
    graphics.setColor(color);
    graphics.setColor(previousColor);

相关文章

Graphics2D类方法