如何让Canvas在Flex中剪辑其内容?
我使用 moveTo 和 lineTo 图形方法在 Canvas 对象上绘制一条线。 如果线的一端位于画布之外,则线会溢出并绘制在应用程序中其他元素的上方或下方。
如何使画布将线条包含在其自身内?
谢谢!
I draw a line on a Canvas object with the moveTo and lineTo graphics methods. If one end of the line lies outside the Canvas, the line spills out and is drawn over or under other elements in the application.
How do I make the Canvas keep the line contained within itself?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
前段时间我也遇到过类似的问题。 您需要在画布中嵌入另一个容器,并在其中绘制原始图形。 我相信这是因为 Canvas 组件仅剪辑子组件,而不是原始图形。
示例如下: http:// /www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=60&catid=585&threadid=1421196。 它包含一些位于页面中间位置的示例代码。
I had a similar problem some time ago. You need to embed another container inside the canvas, and draw the primitive graphics in that instead. I believe this is because the Canvas component only clips child components, and not primitive graphics.
Example here: http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=60&catid=585&threadid=1421196. It includes some sample code about half way down the page.
推荐答案中的链接已损坏。 我通过在画布内放置另一个比外部画布大的画布解决了这个问题。
示例:
如果要在运行时调整窗口 Canvas 的大小,请添加一个调整大小事件侦听器来调整画布 Canvas 的大小。
The link in the recommended answer is broken. I solved the problem by placing another canvas inside my canvas that is larger than the outer canvas.
Example:
If the window Canvas is going to be resized at runtime, add a resize event listener to resize the canvas Canvas also.
我刚刚开发了一个 Flex Box 组件,它充当常规组件容器,但绘制一个圆角矩形背景,另一个圆角矩形表示填充级别。 为此,我需要剪掉不应该被填充的上部部分。 将填充矩形绘制到填充高度是不可能的,因为圆角不匹配。
我学到了什么:
这里是一些代码:
I have just developed a Flex Box component, which acts as a regular component container, but draws a rounded rectangle background, with another rounded rectangle indicated a fill-level. For that I needed to clip the upper section that should not get filled. Drawing the fill rectangle to the fill height was no option since the rounded corners would not match.
What I learned:
Here is some code:
看起来这可能有用:
http://forums.adobe.com/message/199071#199071
Looks like this might be useful:
http://forums.adobe.com/message/199071#199071
将 Canvas 的 ClipToBounds 属性设置为 true:
Set ClipToBounds property of the Canvas to true: