如何在图形对象上绘制填充椭圆?

huangapple go评论81阅读模式
英文:

How to draw a filled oval on a graphics object?

问题

如何在使用<b>BufferedImage</b>创建的<b>Graphics</b>对象上绘制一个红色的填充椭圆,而该图像的背景是填充黑色? <br> <br>
我尝试过的方法:

public void draw(){
    BufferedImage bufferedImage = new BufferedImage(4, 5, BufferedImage.TYPE_INT_ARGB);
    Graphics g = bufferedImage.createGraphics();
    g.setColor(Color.BLACK);
    g.fillRect(0, 0, 4, 5);
    g.setColor(Color.RED);
    g.fillOval(1, 1, 2, 2);
    g.dispose();
}

结果是在一个填充黑色矩形内有一个填充红色矩形:<br>
如何在图形对象上绘制填充椭圆?

但我希填充红色矩形是一个填充红色椭圆。我该如何做到这一点?
<br>
我希望将该图像用作鼠标光标。

英文:

How can I draw a filled oval of color red on a <b>Graphics</b> object created with <b>BufferedImage</b> which is filled with the color black? <br> <br>
What I have tried:

public void draw(){
    BufferedImage bufferedImage = new BufferedImage(4, 5, BufferedImage.TYPE_INT_ARGB);
    Graphics g = bufferedImage.createGraphics();
    g.setColor(Color.BLACK);
    g.fillRect(0, 0, 4, 5);
    g.setColor(Color.RED);
    g.fillOval(1, 1, 2, 2);
    g.dispose();
}

The result is a filled red rectangle in a filled black rectangle: <br>
如何在图形对象上绘制填充椭圆?

But I want that filled red rectangle to be a filled red oval. How can I do that?
<br>
I want to use that image as a mouse cursor.

答案1

得分: 0

看起来像一个红色矩形,因为它只有一个像素的高度和两个像素的宽度。由于没有足够的空间来模拟曲线,所以你不会得到曲线效果。尝试一个更大的椭圆,如 g.fillOval(100, 100, 200, 200);

英文:

It looks like a red rectangle because it is only 1 pixel tall and 2 pixels wide. Since there isn't enough space to simulate a curve, you won't get one. Try a bigger oval like g.fillOval(100, 100, 200, 200);

huangapple
  • 本文由 发表于 2020年10月16日 00:37:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/64376082.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定