如何在Java中绘制绝对自定义形状? [英] How to draw absolutely custom shape in Java?
问题描述
如何做到这一点?
是否可以扩展渲染引擎以绘制更复杂的形状?
UPDATE
实现自定义形状的常用方法是实现 形状
界面。此界面具有用于返回 PathIterator
,而 PathIterator
迭代段类型。只有5种细分类型。其中最弯曲的是 SEG_CUBICTO
,这是标准贝塞尔曲线,带有4个控制点(包括2个开始和结束点)。
如果我将线性分数变换应用于贝塞尔曲线,每个控制点得到一个权重,作为它的坐标的一个补充,并且贝塞尔曲线变成NURBS(对此不确定,未能学习准确的术语)。无论如何,曲线的公式与Bezier不同。
您无法真正扩展渲染引擎:您可以创建Graphics / Graphics2D子类,但是你无法控制实例化,所以你不能强制绘图框架将你的子类传递给绘画方法。
你可以做的是创建一个RationalShape Shape的实现,它具有绘制任何你喜欢的东西的方法,并返回一个PathIterator,它使用Bézier样条曲线来近似。作为像Photoshop这样的图形程序的用户,我发现每个曲线都可以用Bézier样条很好地近似,但我不知道这个近似值背后的数学有多复杂。
The most complex shape, supported by Java2D API is a Bezier segment. Suppose I want to draw rational segment (each control point has a weight and the entire rendering formula is slightly different).
How to accomplish that?
Is it possible to extend rendering engine to be able to draw more complex shapes?
UPDATE
Usual way to implement custom shape is implementing Shape
interface. This interface has key methods to return PathIterator
while PathIterator
iterates over segment types. There are only 5 segment types. The most curved of them is SEG_CUBICTO
which is standard Bezier curve with 4 control points (including 2 for beginning and end).
If I apply linear fractional transform to bezier curve, each control point get a weight, as an addition to it's coordinates, and Bezier curve turns to NURBS (not sure about that, have failed to learn exact terminology). Anyway, the formula for curve differs from Bezier.
You cannot really extend the rendering engine: you can create Graphics/Graphics2D subclasses, but you have no control over the instantiation, so you cannot force the drawing framework to pass your subclass to the painting methods.
What you can do is to create a RationalShape implementation of Shape that has methods that draw anything you like, and returns a PathIterator which approximates it using Bézier splines. As a user of graphical programs like Photoshop I found that every curve can be approximated very well with Bézier splines, I don't know how complicated the math behind this approximation would be.
这篇关于如何在Java中绘制绝对自定义形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!