关于flex中图形的有点奇怪的问题
假设您有一个带有填充和描边的通用 Graphics 对象。是否有一种简单的方法可以对该对象进行切片(例如垂直切片)并获取代表其子集的 Graphics 对象?
换句话说,下面的函数切片会是什么样子?
var gOriginal:Graphics;
var gNew:Graphics;
gNew = slice(gOriginal, "vertical", "0.5);
那么如果 gOriginal 是一个椭圆我现在得到半个椭圆?
谢谢
你
Let's say you have a generic Graphics object with a fill and a a stroke. Is there an easy way to slice that object, for instance vertically, and get a Graphics object that represents a subset of it?
In other words, what would function slice below look like?
var gOriginal:Graphics;
var gNew:Graphics;
gNew = slice(gOriginal, "vertical", "0.5);
so that if gOriginal was an ellipse I now get half an ellipse?
thank you
f
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我基本上是在标记丹尼尔的概念(除了我有一些根深蒂固的、无法解释的、对 degrafa 的蔑视),你应该能够做到这一点:
这显然不是一个漂亮的解决方案,但只是将图形制作到一些具有图形属性,然后使用 BitmapData 绘制方法将像素放入位图数据中,然后将这些像素的一部分复制到另一个 BitmapData 中进行显示,这可能比 Jeremy 的方法占用更多内存,但占用的处理器更少。另外,我正在使用 UIComponent,绘制方法的要求是该类实现 IBitmapDrawable,因此无论最轻的实现是什么,都可能是您想要使用的,UIComponent 是一个猜测。
I'm tagging onto Daniel's concept basically (except I have some deeply rooted, unexplained, disdain for degrafa), you should be able to do this:
This is obviously far from a pretty solution but just doing the graphics into some object that has a graphics property, then using the BitmapData draw method to get the pixels into a bitmap data then copying out a section of those pixels to another BitmapData for display, this is probably more memory but less processor intensive than Jeremy's. Also I'm using UIComponent the requirement for the draw method is that the class implements IBitmapDrawable so whatever is the lightest implementation of that is probably what you want to use, UIComponent is a guess.
您可以将其绘制()到位图对象中并选择要包含的矩形,这可以具有相同的效果,但没有简单的方法可以做到这一点。
您还可以查看 degrafa 但这可能会变得太复杂
you could draw() it into a bitmap object and select a rectangle to include which could have the same effect, but there is no simple way of doing that.
you can also look into degrafa but that could become too complicated
没有用于删除
Graphics
对象部分的内置方法。在“切片”方面,您很可能需要独特地对待每种类型的形状(矩形、椭圆形、多边形)。例如,要对椭圆进行切片,与从饼图中切出切片类似,您需要使用一点三角函数来绘制形状以创建楔形。以下是绘制楔形的基本函数:
在初始化时调整
angleX
和angleY
变量将开始在圆周上的不同点绘制楔形。如果将度
更改为 360,您将看到一个完整的圆,如果更改为 180,您将看到半圆。更改radiusX
和radiusY
以创建椭圆形。此外,segments
控制绘图的分辨率。提高它,你会得到更平滑的曲线。希望这有帮助。
There isn't a built in method for removing portions of a
Graphics
object. You will most likely need to treat each type of shape ( rect, ellipse, poly ) uniquely, in regard to "slicing" it. For instance to slice an elipse, similarly to taking a slice out of a pie chart, you would need to draw the shapes using a little trig to create a wedge.Here is a basic function for drawing wedges:
Adjusting the
angleX
andangleY
vars when they are initialized will begin drawing the wedge at a different point along the circumference. If you changedegrees
to 360 you will see a complete circle, and at 180 you will get a half circle. ChangeradiusX
andradiusY
to create an oval. Also,segments
controls the resolution of the drawing. Bump it up and you get a smoother curve.Hope this helps.