绘制图像的一部分(Java) [英] Drawing a part of an image (Java)
问题描述
这是我的问题 - 我试图绘制单个图像的圆形部分。
我正在做一些自上而下的地牢爬行器类游戏,我试图在玩家周围做一个光线半径。地板是一个单一的图像,我只需要画一个小的圆形部分。我一直在看这个方法:
drawImage(Image img,
int dx1,
int dy1,
int dx2,
int dy2,
int sx1,
int sy1,
int sx2,
int sy2,
颜色bgcolor ,
ImageObserver观察者)
但是,看起来它只会画一个方形的小节。
有人碰巧知道一个更简单的方法,而不是画一大堆小方块来给出一个圆圈的幻觉吗?
谢谢
您可以使用中的 setClip()
docs.oracle.com/javase/1.4.2/docs/api/java/awt/Graphics.htmlrel =nofollow> Graphics
。
它需要一些其他的工作,但是:
import java.awt .Graphics;
import java.awt.geom.QuadCurve2D;
// ...
g.setClip(new QuadCurve()); //设置图像的边界曲线。
g.drawImage(...);
正如我所说的,它需要更多的工作,这意味着 QuadCurve2D
对象可能需要以不同的方式定义,但您可以检查文档。
Here's my problem- I'm trying to draw a circular part of a single image.
I'm doing some work on a top-down dungeon crawler sort of game, and I'm attempting to make a light radius around the player. The floor is a single image, and I need to draw only a small, circular part of it. I've been looking at this method:
drawImage(Image img,
int dx1,
int dy1,
int dx2,
int dy2,
int sx1,
int sy1,
int sx2,
int sy2,
Color bgcolor,
ImageObserver observer)
But, that looks like it would only draw a square subsection. Does anyone happen to know an easier method than drawing tons of little squares to give the illusion of a circle?
Thanks
You can do this with the setClip()
method in Graphics
.
It needs some other work, but:
import java.awt.Graphics;
import java.awt.geom.QuadCurve2D;
//...
g.setClip(new QuadCurve()); // Set the bounding curve for the image.
g.drawImage(...);
As I said, it needs more work, meaning the QuadCurve2D
object might need to be defined differently, but you can check the doc for that.
这篇关于绘制图像的一部分(Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!