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

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

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

Graphics2D.dispose介绍

暂无

代码示例

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

private static BufferedImage createImage (int width, int height, Color color) {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D g = image.createGraphics();
    g.setColor(color);
    g.fillRect(0, 0, width, height);
    g.dispose();
    return image;
  }
}

代码示例来源:origin: linlinjava/litemall

private void drawImgInImg(BufferedImage baseImage, BufferedImage imageToWrite, int x, int y, int width, int heigth) {
    Graphics2D g2D = (Graphics2D) baseImage.getGraphics();
    g2D.drawImage(imageToWrite, x, y, width, heigth, null);
    g2D.dispose();
  }
}

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

/**
 * Creates an empty image.
 *
 * @param width width of image
 * @param height height of image
 * @return empty image
 */
public static ImageIcon createEmptyImageIcon(final int width, final int height) {
  final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE);
  final Graphics2D g = image.createGraphics();
  g.dispose();
  return new ImageIcon(image);
}

代码示例来源:origin: stackoverflow.com

BufferedImage dest = new BufferedImage(
  imageWidth, imageHeight,
  BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = dest.createGraphics();
g2.drawImage(image, 0, 0, null);
g2.dispose();

代码示例来源:origin: MovingBlocks/Terasology

@Override
public void render(BufferedImage img, Region region) {
  TreeFacet treeFacet = region.getFacet(TreeFacet.class);
  Graphics2D g = img.createGraphics();
  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  for (Entry<BaseVector3i, TreeGenerator> entry : treeFacet.getRelativeEntries().entrySet()) {
    TreeGenerator treeGen = entry.getValue();
    int wx = entry.getKey().getX();
    int wz = entry.getKey().getZ();
    int r = radiusFunc.apply(treeGen);
    Color color = colorFunc.apply(treeGen);
    // the fill area is offset by +1/+1 pixel
    // otherwise it will bleed out at the top left corner
    g.setColor(color);
    g.fillOval(wx - r + 1, wz - r + 1, r * 2 - 1, r * 2 - 1);
    g.setColor(color.darker());
    g.drawOval(wx - r, wz - r, r * 2, r * 2);
  }
  g.dispose();
}

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

@Override
protected void renderSimple( BufferedImage area ) {
 Graphics2D gc = createGraphics( area );
 render( gc, area.getWidth() / 2, area.getHeight() / 2, area.getWidth(), area.getHeight(), 0 );
 gc.dispose();
}

代码示例来源:origin: linlinjava/litemall

private void drawTextInImg(BufferedImage baseImage, String textToWrite, int x, int y) {
  Graphics2D g2D = (Graphics2D) baseImage.getGraphics();
  g2D.setColor(new Color(167, 136, 69));
  //TODO 注意,这里的字体必须安装在服务器上
  g2D.setFont(new Font("Microsoft YaHei", Font.PLAIN, 28));
  g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g2D.drawString(textToWrite, x, y);
  g2D.dispose();
}

代码示例来源:origin: wuyouzhuguli/FEBS-Shiro

/**
 * 画随机码图
 *
 * @param fontcolor 随机字体颜色
 * @param strs      字符数组
 * @param flag      透明度使用
 * @return BufferedImage
 */
private BufferedImage graphicsImage(Color[] fontcolor, char[] strs, int flag) {
  BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
  // 或得图形上下文
  Graphics2D g2d = (Graphics2D) image.getGraphics();
  // 利用指定颜色填充背景
  g2d.setColor(Color.WHITE);
  g2d.fillRect(0, 0, width, height);
  AlphaComposite ac3;
  int h = height - ((height - font.getSize()) >> 1);
  int w = width / len;
  g2d.setFont(font);
  for (int i = 0; i < len; i++) {
    ac3 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getAlpha(flag, i));
    g2d.setComposite(ac3);
    g2d.setColor(fontcolor[i]);
    g2d.drawOval(num(width), num(height), 5 + num(10), 5 + num(10));
    g2d.drawString(strs[i] + "", (width - (len - i) * w) + (w - font.getSize()) + 1, h - 4);
  }
  g2d.dispose();
  return image;
}

代码示例来源:origin: linlinjava/litemall

private void drawTextInImgCenter(BufferedImage baseImage, String textToWrite, int y) {
  Graphics2D g2D = (Graphics2D) baseImage.getGraphics();
  g2D.setColor(new Color(167, 136, 69));
  String fontName = "Microsoft YaHei";
  Font f = new Font(fontName, Font.PLAIN, 28);
  g2D.setFont(f);
  g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  // 计算文字长度,计算居中的x点坐标
  FontMetrics fm = g2D.getFontMetrics(f);
  int textWidth = fm.stringWidth(textToWrite);
  int widthX = (baseImage.getWidth() - textWidth) / 2;
  // 表示这段文字在图片上的位置(x,y) .第一个是你设置的内容。
  g2D.drawString(textToWrite, widthX, y);
  // 释放对象
  g2D.dispose();
}

代码示例来源:origin: stackoverflow.com

if (dragOver) {
  Graphics2D g2d = (Graphics2D) g.create();
  g2d.setColor(new Color(0, 255, 0, 64));
  g2d.fill(new Rectangle(getWidth(), getHeight()));
  if (dragPoint != null && target != null) {
    int x = dragPoint.x - 12;
    int y = dragPoint.y - 12;
    g2d.drawImage(target, x, y, this);
  g2d.dispose();

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

private static BufferedImage createImage (int width, int height, Color color) {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D g = image.createGraphics();
    g.setColor(color);
    g.fillRect(0, 0, width, height);
    g.dispose();
    return image;
  }
}

代码示例来源:origin: looly/hutool

/**
 * 将图片绘制在背景上
 * 
 * @param backgroundImg 背景图片
 * @param img 要绘制的图片
 * @param rectangle 矩形对象,表示矩形区域的x,y,width,height,x,y从背景图片中心计算
 * @return 绘制后的背景
 */
private static BufferedImage draw(BufferedImage backgroundImg, Image img, Rectangle rectangle, float alpha) {
  final Graphics2D g = backgroundImg.createGraphics();
  g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
  g.drawImage(img, rectangle.x, rectangle.y, rectangle.width, rectangle.height, null); // 绘制切割后的图
  g.dispose();
  return backgroundImg;
}

代码示例来源:origin: mabe02/lanterna

/**
 * Clears out the back buffer and the resets the visual state so next paint operation will do a full repaint of
 * everything
 */
private void clearBackBuffer() {
  // Manually clear the backbuffer
  if(backbuffer != null) {
    Graphics2D graphics = backbuffer.createGraphics();
    Color backgroundColor = colorConfiguration.toAWTColor(TextColor.ANSI.DEFAULT, false, false);
    graphics.setColor(backgroundColor);
    graphics.fillRect(0, 0, getWidth(), getHeight());
    graphics.dispose();
  }
}

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

@Override
 protected Image renderRotated( Device device, int width, int height, double angleRadians ) {
  BufferedImage doubleArea = SwingUniversalImage.createDoubleBitmap( width, height );

  Graphics2D gc = SwingUniversalImage.createGraphics( doubleArea );
  SwingUniversalImageSvg.render( gc, svgGraphicsNode, svgGraphicsSize, doubleArea.getWidth() / 2, doubleArea
    .getHeight() / 2, width, height, angleRadians );

  gc.dispose();

  return swing2swt( device, doubleArea );
 }
}

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

/**
 * Creates a rectangular mono colored image.
 *
 * @param paint color of the image
 * @param width width of the image
 * @param height height of the image
 * @return mono colored rectangular image
 */
public static ImageIcon createMonoColoredImageIcon(final Paint paint, final int width, final int height) {
  final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE);
  final Graphics2D g = image.createGraphics();
  g.setPaint(paint);
  final int lineHeight = 4;
  g.fill3DRect(0, height / 2 - lineHeight / 2, width, lineHeight, false);
  g.dispose();
  return new ImageIcon(image);
}

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

public void draw (BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) {
  g = (Graphics2D)g.create();
  if (stroke != null)
    g.setStroke(stroke);
  else
    g.setStroke(getStroke());
  g.setColor(color);
  g.draw(glyph.getShape());
  g.dispose();
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D)image.getGraphics();
g2.setColor(Color.lightGray);
g2.fillRect(0, 0, width, height);
g2.setColor(Color.cyan);
g2.drawRect(0, 0, width, height);
g2.setColor(new Color(0, 0, 128));
g2.dispose();

代码示例来源:origin: nutzam/nutz

/**
 * 在一个RGB画布上重新绘制Image,解决CMYK图像偏色的问题
 */
public static BufferedImage redraw(BufferedImage img, Color bg) {
  BufferedImage rgbImage = new BufferedImage(img.getWidth(),
                        img.getHeight(),
                        BufferedImage.TYPE_3BYTE_BGR);
  Graphics2D g2d = rgbImage.createGraphics();
  g2d.drawImage(img, 0, 0, bg, null);
  g2d.dispose();
  return rgbImage;
}

代码示例来源:origin: stackoverflow.com

private Image getScaledImage(Image srcImg, int w, int h){
  BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
  Graphics2D g2 = resizedImg.createGraphics();

  g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  g2.drawImage(srcImg, 0, 0, w, h, null);
  g2.dispose();

  return resizedImg;
}

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

protected void drawGraphic(String randomString, BufferedImage image){
  Graphics2D g = image.createGraphics();
  g.setColor(getRandColor(210, 250));
  g.fillRect(0, 0, WIDTH, HEIGHT);
  for(int i = 0; i < 20; i++){
    color = getRandColor(120, 200);
    g.setColor(color);
    String rand = String.valueOf(charArray[random.nextInt(charArray.length)]);
    g.drawString(rand, random.nextInt(WIDTH), random.nextInt(HEIGHT));
    g.setColor(color);
  g.draw(curve);
  g.dispose();

相关文章

Graphics2D类方法