英文:
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>
我希望将该图像用作鼠标光标。
英文:
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论