本文整理了Java中java.awt.Graphics2D.fillRect()
方法的一些代码示例,展示了Graphics2D.fillRect()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graphics2D.fillRect()
方法的具体详情如下:
包路径:java.awt.Graphics2D
类名称:Graphics2D
方法名:fillRect
暂无
代码示例来源: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: libgdx/libgdx
/** Returns an image that can be used by effects as a temp image. */
static public BufferedImage getScratchImage () {
Graphics2D g = (Graphics2D)scratchImage.getGraphics();
g.setComposite(AlphaComposite.Clear);
g.fillRect(0, 0, GlyphPage.MAX_GLYPH_SIZE, GlyphPage.MAX_GLYPH_SIZE);
g.setComposite(AlphaComposite.SrcOver);
g.setColor(java.awt.Color.white);
return scratchImage;
}
代码示例来源:origin: libgdx/libgdx
protected void paintComponent (Graphics graphics) {
Graphics2D g = (Graphics2D)graphics;
int width = getWidth() - 1;
int height = getHeight() - 1;
for (int i = 0, n = paletteColors.length - 1; i < n; i++) {
Color color1 = paletteColors[i];
Color color2 = paletteColors[i + 1];
float point1 = i / (float)n * width;
float point2 = (i + 1) / (float)n * width;
g.setPaint(new GradientPaint(point1, 0, color1, point2, 0, color2, false));
g.fillRect((int)point1, 0, (int)Math.ceil(point2 - point1), height);
}
g.setPaint(null);
g.setColor(Color.black);
g.drawRect(0, 0, width, height);
}
}
代码示例来源:origin: runelite/runelite
private void redrawGradient()
{
Color primaryRight = Color.getHSBColor(1f - this.selectedY / (float) (size - 1), 1, 1);
Graphics2D g = image.createGraphics();
GradientPaint primary = new GradientPaint(
0f, 0f, Color.WHITE,
size - 1, 0f, primaryRight);
GradientPaint shade = new GradientPaint(
0f, 0f, new Color(0, 0, 0, 0),
0f, size - 1, Color.BLACK);
g.setPaint(primary);
g.fillRect(0, 0, size, size);
g.setPaint(shade);
g.fillRect(0, 0, size, size);
g.dispose();
forceRedraw = true;
}
代码示例来源:origin: sarxos/webcam-capture
private void drawRect(Graphics2D g2, int w, int h) {
int rx = (int) (w * Math.random() / 1.5);
int ry = (int) (h * Math.random() / 1.5);
int rw = (int) (w * Math.random() / 1.5);
int rh = (int) (w * Math.random() / 1.5);
g2.setColor(new Color((int) (Integer.MAX_VALUE * Math.random())));
g2.fillRect(rx, ry, rw, rh);
}
代码示例来源:origin: stackoverflow.com
Graphics2D g2 = (Graphics2D)g;
g2.setColor( black );
g2.drawRoundRect( 1, 1, getWidth()-2 - 1, getHeight()-2 - 1, 2,2 );
g2.setColor( white );
g2.drawRoundRect( 1 + 1, 1 + 1, getWidth()-2 - 3, getHeight()-2 - 3, 2,2 );
int h = thumbBounds.height;
g2.setPaint( new GradientPaint(x, (int)(y-0.1*h), colorDark , x, (int)(y+1.2*h), light) );
g2.fillRect( x, y, w, h );
g2.setPaint( new GradientPaint(x, (int)(y+.65*h), light , x, (int)(y+1.3*h), colorDark) );
g2.fillRect( x, (int)(y+.65*h), w, (int)(h-.65*h) );
g2.setColor( colorBright );
g2.fillRect(x+w/2-size/2,y+h/2-size/2, size, size);
g2.setColor( new Color(120,120,120));
g2.fillRect(x+w/2-4,h/2-4, 2, 2);
g2.fillRect(x+w/2-1,h/2-4, 2, 2);
g2.fillRect(x+w/2+2,h/2-4, 2, 2);
g2.setColor( colorDark );
g2.fillRect(x+w/2-4,h/2-2, 2, 6);
g2.fillRect(x+w/2-1,h/2-2, 2, 6);
g2.fillRect(x+w/2+2,h/2-2, 2, 6);
g2.setColor( new Color(170,170,170));
g2.fillRect(x+w/2-4,h/2+2, 2, 2);
g2.fillRect(x+w/2-1,h/2+2, 2, 2);
g2.fillRect(x+w/2+2,h/2+2, 2, 2);
代码示例来源: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: chewiebug/GCViewer
g2d.setPaint(Color.BLACK);
g2d.setPaint(Color.BLUE);
g2d.setPaint(Color.ORANGE);
g2d.setPaint(getLinePaint());
g2d.fillRect(x, y, width, height);
代码示例来源:origin: i2p/i2p.i2p
public void loadImage(String imageFile) throws IOException {
BufferedImage wpImage = ImageIO.read(new File(imageFile));
TexturePaint paint = new TexturePaint(wpImage, new Rectangle(0, 0, wpImage.getWidth(), wpImage.getHeight()));
gd.setPaint(paint);
gd.fillRect(0, 0, wpImage.getWidth(), wpImage.getHeight());
}
}
代码示例来源:origin: tomighty/tomighty
private void paintBackground(Graphics2D graphics, AbstractButton b) {
Graphics2D g = (Graphics2D) graphics.create();
try {
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
Color startingColor = look.colors().shadow().brighter().brighter();
Color endingColor = look.colors().shadow().darker();
g.setPaint(new GradientPaint(0, 0, startingColor, 0, b.getHeight(), endingColor));
g.fillRect(1, 1, b.getWidth()-2, b.getHeight()-2);
} finally {
g.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: vert-x3/vertx-examples
public Image(Vertx vertx, String name) {
try {
final BufferedImage raster = ImageIO.read(((VertxInternal) vertx).resolveFile(name));
width = raster.getWidth();
height = raster.getHeight();
data = raster.getRGB(0, 0, width, height, null, 0, width);
for (int pixel : data)
if (!colorMap.containsKey(pixel)) {
BufferedImage offlineImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = offlineImage.createGraphics();
g2.setPaint(new Color(pixel, true));
g2.fillRect(0, 0, 1, 1);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageIO.write(offlineImage, "PNG", out);
colorMap.put(pixel, Buffer.buffer().appendBytes(out.toByteArray()));
out.close();
g2.dispose();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源: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: libgdx/libgdx
protected void paintComponent (Graphics graphics) {
Graphics2D g = (Graphics2D)graphics;
int width = getWidth() - 1;
int height = getHeight() - 1;
for (int i = 0, n = paletteColors.length - 1; i < n; i++) {
Color color1 = paletteColors[i];
Color color2 = paletteColors[i + 1];
float point1 = i / (float)n * width;
float point2 = (i + 1) / (float)n * width;
g.setPaint(new GradientPaint(point1, 0, color1, point2, 0, color2, false));
g.fillRect((int)point1, 0, (int)Math.ceil(point2 - point1), height);
}
g.setPaint(null);
g.setColor(Color.black);
g.drawRect(0, 0, width, height);
}
}
代码示例来源: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: libgdx/libgdx
/** Returns an image that can be used by effects as a temp image. */
static public BufferedImage getScratchImage () {
Graphics2D g = (Graphics2D)scratchImage.getGraphics();
g.setComposite(AlphaComposite.Clear);
g.fillRect(0, 0, GlyphPage.MAX_GLYPH_SIZE, GlyphPage.MAX_GLYPH_SIZE);
g.setComposite(AlphaComposite.SrcOver);
g.setColor(java.awt.Color.white);
return scratchImage;
}
代码示例来源:origin: magefree/mage
protected void drawCardBack(Graphics2D g) {
g.setPaint(BG_TEXTURE_CARDBACK);
g.fillRect(borderWidth, borderWidth,
cardWidth - 2 * borderWidth, cardHeight - 2 * borderWidth);
}
代码示例来源:origin: looly/hutool
/**
* 创建{@link Graphics2D}
*
* @param image {@link BufferedImage}
* @param color {@link Color}背景颜色以及当前画笔颜色
* @return {@link Graphics2D}
* @since 3.2.3
*/
public static Graphics2D createGraphics(BufferedImage image, Color color) {
final Graphics2D g = image.createGraphics();
// 填充背景
g.setColor(color);
g.fillRect(0, 0, image.getWidth(), image.getHeight());
return g;
}
代码示例来源:origin: tomighty/tomighty
private void paintGradient(Color start, Color end, int y1, int y2) {
Graphics2D graphics = image.createGraphics();
try {
graphics.setPaint(new GradientPaint(0, y1, start, 0, y2, end));
graphics.fillRect(0, y1, width, y2);
} finally {
graphics.dispose();
}
}
代码示例来源:origin: marytts/marytts
protected void drawSpectrum(Graphics2D g, double[] spectrum, int image_X, int image_width, int image_refY, int image_height) {
double yScaleFactor = (double) image_height / spectra_indexmax;
if (image_width < 2)
image_width = 2;
int rect_height = (int) Math.ceil(yScaleFactor);
if (rect_height < 2)
rect_height = 2;
for (int i = 0; i < spectra_indexmax; i++) {
int color;
if (Double.isNaN(spectrum[i]) || spectrum[i] < spectra_max - DYNAMIC_RANGE) {
color = 255; // white
} else {
color = (int) (255 * (spectra_max - spectrum[i]) / DYNAMIC_RANGE);
}
g.setColor(new Color(color, color, color));
g.fillRect(image_X, image_refY - (int) (i * yScaleFactor), image_width, rect_height);
}
}
内容来源于网络,如有侵权,请联系作者删除!