java随机创建形状,如何在Java中绘制绝对自定义形状?

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值