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

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

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

Graphics2D.setBackground介绍

暂无

代码示例

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

@Override
public void setBounds(Rectangle bounds) {
  if (image == null || image.getHeight() != bounds.height || image.getWidth() != bounds.width) {
    image = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_INT_ARGB);
    tmpG = image.createGraphics();
    tmpG.setColor(Color.BLACK);
    tmpG.setBackground(Color.WHITE);
  }
  this.bounds = bounds;
  repaint();
}

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

public static BufferedImage transformImage(BufferedImage image, AffineTransform transform) throws Exception {

  AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BICUBIC);

  BufferedImage destinationImage = op.createCompatibleDestImage(image, (image.getType() == BufferedImage.TYPE_BYTE_GRAY) ? image.getColorModel() : null );
  Graphics2D g = destinationImage.createGraphics();
  g.setBackground(Color.WHITE);
  g.clearRect(0, 0, destinationImage.getWidth(), destinationImage.getHeight());
  destinationImage = op.filter(image, destinationImage);
  return destinationImage;
}

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

@Path("discrete")
@GET
public Response discrete(
    @DefaultValue("2") @QueryParam("width") final int width,
    @DefaultValue("50") @QueryParam("upper") final int upper,
    @DefaultValue("red") @QueryParam("upper-color") final ColorParam upperColor,
    @DefaultValue("gray") @QueryParam("lower-color") final ColorParam lowerColor
) {
  final BufferedImage image = new BufferedImage(
      data.size() * width - 1, imageHeight, BufferedImage.TYPE_INT_RGB);
  final Graphics2D g = image.createGraphics();
  g.setBackground(Color.WHITE);
  g.clearRect(0, 0, image.getWidth(), image.getHeight());
  final int gap = 4;
  final float d = (limits.width() + 1) / (float) (imageHeight - gap);
  for (int i = 0, x = 0, y; i < data.size(); i++, x += width) {
    final int v = data.get(i);
    g.setColor((v >= upper) ? upperColor : lowerColor);
    y = imageHeight - (int) ((v - limits.lower()) / d);
    g.drawRect(x, y - gap, width - 2, gap);
  }
  return Response.ok(image).tag(tag).build();
}

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

private void drawImage( SwingUniversalImage img, int locationX, int locationY, int imageSize ) {
 if ( isDrawingPixelatedImages() && img.isBitmap() ) {
  BufferedImage bi = new BufferedImage( imageSize, imageSize, BufferedImage.TYPE_INT_ARGB );
  Graphics2D g2 = (Graphics2D) bi.getGraphics();
  g2.setColor( Color.WHITE );
  g2.fillRect( 0, 0, imageSize, imageSize );
  g2.drawImage( img.getAsBitmapForSize( imageSize, imageSize ), 0, 0, observer );
  g2.dispose();
  for ( int x = 0; x < bi.getWidth( observer ); x++ ) {
   for ( int y = 0; y < bi.getHeight( observer ); y++ ) {
    int rgb = bi.getRGB( x, y );
    gc.setColor( new Color( rgb ) );
    gc.setStroke( new BasicStroke( 1.0f ) );
    gc.drawLine( locationX + xOffset + x, locationY + yOffset + y, locationX + xOffset + x, locationY
     + yOffset + y );
   }
  }
 } else {
  gc.setBackground( Color.white );
  gc.clearRect( locationX, locationY, imageSize, imageSize );
  img.drawToGraphics( gc, locationX, locationY, imageSize, imageSize );
 }
}

代码示例来源:origin: prestodb/presto

final int PAD = 20;
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
g.setBackground(Color.WHITE);
g.setColor(Color.BLACK);
g.drawString(labelDense, WIDTH / 2 - 50, 2 * GRAPH_HEIGHT + EXT_PAD + 2 * PAD + 20);

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

public BufferedImage scaleImage(BufferedImage img, int width, int height,
    Color background) {
  int imgWidth = img.getWidth();
  int imgHeight = img.getHeight();
  if (imgWidth*height < imgHeight*width) {
    width = imgWidth*height/imgHeight;
  } else {
    height = imgHeight*width/imgWidth;
  }
  BufferedImage newImage = new BufferedImage(width, height,
      BufferedImage.TYPE_INT_RGB);
  Graphics2D g = newImage.createGraphics();
  try {
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
        RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g.setBackground(background);
    g.clearRect(0, 0, width, height);
    g.drawImage(img, 0, 0, width, height, null);
  } finally {
    g.dispose();
  }
  return newImage;
}

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

@DefaultValue("red") @QueryParam("last-color") final ColorParam lastColor
) {
  final BufferedImage image = new BufferedImage(
      data.size() * step - 4, imageHeight, BufferedImage.TYPE_INT_RGB);
  final Graphics2D g = image.createGraphics();
  g.setBackground(Color.WHITE);
  g.clearRect(0, 0, image.getWidth(), image.getHeight());

代码示例来源:origin: deeplearning4j/dl4j-examples

if (currShape < numShapes - 1 && i >= startFrames[currShape + 1]) currShape++;
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bi.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setBackground(Color.BLACK);

代码示例来源:origin: redwarp/9-Patch-Resizer

private void enforceBorderColors(BufferedImage inputImage) {
 Graphics2D g = inputImage.createGraphics();
 g.setBackground(new Color(0, 0, 0, 0));
 g.clearRect(1, 1, inputImage.getWidth() - 2, inputImage.getHeight() - 2);
 g.dispose();
 int w = inputImage.getWidth();
 int h = inputImage.getHeight();
 int[] rgb = new int[w * h];
 inputImage.getRGB(0, 0, w, h, rgb, 0, w);
 for (int i = 0; i < rgb.length; i++) {
  if ((0xff000000 & rgb[i]) != 0) {
   rgb[i] = 0xff000000;
  }
 }
 inputImage.setRGB(0, 0, w, h, rgb, 0, w);
 inputImage.setRGB(0, 0, 0x0);
 inputImage.setRGB(0, h - 1, 0x0);
 inputImage.setRGB(w - 1, h - 1, 0x0);
 inputImage.setRGB(w - 1, 0, 0x0);
}

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

public void render(GCModel model, FileOutputStream outputStream) throws IOException {
  GCPreferences gcPreferences = new GCPreferences();
  gcPreferences.load();
  Dimension d = new Dimension(gcPreferences.getWindowWidth(), gcPreferences.getWindowHeight());
  BufferedImage image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB);
  Graphics2D graphics = image.createGraphics();
  graphics.setBackground(Color.WHITE);
  graphics.clearRect(0, 0, image.getWidth(), image.getHeight());
  ChartDrawingParameters params
      = new ChartDrawingParameters(model, gcPreferences, d, graphics, image, outputStream);
  if (EventQueue.isDispatchThread()) {
    drawAndSaveToStream(params);
  }
  else {
    new SwingChartToStreamHelper().execute(params);
  }
}

代码示例来源:origin: nguyenq/tess4j

cy = (cy - minY);
BufferedImage bi = new BufferedImage((maxX - minX), (maxY - minY),
    image.getType());
Graphics2D g2 = bi.createGraphics();
    RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2.setBackground(Color.white);
g2.fillRect(0, 0, bi.getWidth(), bi.getHeight());

代码示例来源:origin: loklak/loklak_server

/**
 * Deletes all pixels of image and sets them to previously defined
 * background color.
 */
public final void clear() {
  // fill grid with background color
  final int bgR = (int) (this.backgroundCol >> 16);
  final int bgG = (int) ((this.backgroundCol >> 8) & 0xff);
  final int bgB = (int) (this.backgroundCol & 0xff);
  if (this.frame == null) {
    final Graphics2D gr = this.image.createGraphics();
    Color c = new Color(bgR, bgG, bgB);
    gr.setBackground(c);
    gr.clearRect(0, 0, this.width, this.height);
    gr.setColor(c);
    gr.fillRect(0, 0, this.width, this.height);
  } else {
    int p = 0;
    for (int i = 0; i < width; i++) {
      this.frame[p++] = (byte) bgR;
      this.frame[p++] = (byte) bgG;
      this.frame[p++] = (byte) bgB;
    }
    final int rw = width * 3;
    for (int i = 1; i < height; i++) {
      System.arraycopy(this.frame, 0, this.frame, i * rw, rw);
    }
  }
}

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

int height = (int) (scale * sz.getHeight());
BufferedImage img = new BufferedImage(width, height,
    BufferedImage.TYPE_INT_RGB);
final Graphics2D graphics = img.createGraphics();
graphics.setBackground(Color.white);
graphics.clearRect(0, 0, width, height);

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

private static final Stroke BIMAGE_DRAW_STROKE = new BasicStroke(4);
private static final int COLOR_DIV = 5;
private BufferedImage bImage = new BufferedImage(BI_WIDTH, BI_HEIGHT,
    BufferedImage.TYPE_INT_RGB);
private List<Point> pointList = new ArrayList<Point>();
 g2d.setBackground(Color.white);
 g2d.clearRect(0, 0, BI_WIDTH, BI_HEIGHT);
 g2d.dispose();
   public void actionPerformed(ActionEvent e) {
    Graphics2D g2 = bImage.createGraphics();
    g2.setBackground(Color.white);
    g2.clearRect(0, 0, BI_WIDTH, BI_HEIGHT);
    g2.dispose();

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

private void drawImage( SwingUniversalImage img, int centerX, int centerY, double angle, int imageSize ) {
 if ( isDrawingPixelatedImages() && img.isBitmap() ) {
  BufferedImage bi =  img.getAsBitmapForSize( imageSize, imageSize, angle );
  int offx = centerX + xOffset - bi.getWidth() / 2;
  int offy = centerY + yOffset - bi.getHeight() / 2;
  for ( int x = 0; x < bi.getWidth( observer ); x++ ) {
   for ( int y = 0; y < bi.getHeight( observer ); y++ ) {
    int rgb = bi.getRGB( x, y );
    gc.setColor( new Color( rgb ) );
    gc.setStroke( new BasicStroke( 1.0f ) );
    gc.drawLine( offx + x, offy + y, offx + x, offy + y );
   }
  }
 } else {
  gc.setBackground( Color.white );
  gc.clearRect( centerX, centerY, imageSize, imageSize );
  img.drawToGraphics( gc, centerX, centerY, imageSize, imageSize, angle );
 }
}

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

fixedColor = Color.WHITE;
final BufferedImage image = new BufferedImage(width, height, getTypeInt());
Graphics2D g = image.createGraphics();
g.setBackground(fixedColor);
g.clearRect(0, 0, width, height);

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

BufferedImage gridImage = new BufferedImage(width, height,
   BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = gridImage.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
   RenderingHints.VALUE_ANTIALIAS_ON);
g2.setBackground(BACKGROUND);
g2.clearRect(0, 0, width, height);

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

g2.setBackground(new Color(Math.abs(r++), Math.abs(g++), Math.abs(b++)));
g2.clearRect(0, 0, w, h);

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

fixedColor = Color.WHITE;
final BufferedImage image = new BufferedImage(width, height, getTypeInt());
Graphics2D g = image.createGraphics();
g.setBackground(fixedColor);
g.clearRect(0, 0, width, height);

代码示例来源:origin: com.silicolife.textmining/core

public static Image getScaledImage(Image srcImg, final int w, final int h){
  BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
  Graphics2D g2 = resizedImg.createGraphics();
  g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  g2.drawImage(srcImg, 0, 0, w, h, null);
  Color color = Color.GRAY;
  g2.setBackground(color);
  g2.dispose();
  return resizedImg;
}

相关文章

Graphics2D类方法