如何使用 BitmapData 用铅笔绘图?
现在我只有这段代码,但我没有使用 BitmapData.draw()
。如何使用 BitmapData.draw()
编写代码?
penSprite.graphics.lineStyle(3,045666);
addChild(penSprite);
addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
addEventListener(MouseEvent.MOUSE_UP, mouseUp);
penSprite = new Sprite(); //var penSprite:Sprite = new Sprite();
mouseDownFlag = new Boolean(); //var mouseDownFlag:Boolean = false;
private function mouseDown(e:MouseEvent):void
{
penSprite.graphics.moveTo(e.localX, e.localY);
mouseDownFlag = true;
}
private function mouseMove(e:MouseEvent):void
{
if (mouseDownFlag) penSprite.graphics.lineTo(e.localX, e.localY);
}
private function mouseUp(e:MouseEvent):void
{
mouseDownFlag = false;
}
Right now I only have this code, but I'm not using BitmapData.draw()
. How can I write my code using BitmapData.draw()
?
penSprite.graphics.lineStyle(3,045666);
addChild(penSprite);
addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
addEventListener(MouseEvent.MOUSE_UP, mouseUp);
penSprite = new Sprite(); //var penSprite:Sprite = new Sprite();
mouseDownFlag = new Boolean(); //var mouseDownFlag:Boolean = false;
private function mouseDown(e:MouseEvent):void
{
penSprite.graphics.moveTo(e.localX, e.localY);
mouseDownFlag = true;
}
private function mouseMove(e:MouseEvent):void
{
if (mouseDownFlag) penSprite.graphics.lineTo(e.localX, e.localY);
}
private function mouseUp(e:MouseEvent):void
{
mouseDownFlag = false;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是基于您的代码的代码示例。您可以通过将其设为电影的基类来尝试一下。
}
Here's the code sample based on you code. You try it out by just making it a base class of the movie.
}
好吧,你的问题不是很清楚,我想你想将你的内容复制到位图中。
如果这就是您想要实现的目标,只需创建一个新的 bitmapData,在其中绘制精灵并将其用作位图的源即可。
例如,当您完成在 penSprite 中绘制时,您可以将其复制到位图中,如下所示:
希望这就是您正在寻找的。
编辑:
我看到您只是在问题中添加了一条评论,说您想绘制“使用 bitmapData.draw”。所以,我认为您误解了该方法的使用。如果您查看文档:
“使用 Flash 运行时矢量渲染器将源显示对象绘制到位图图像上。”
那么您基本上可以使用它在 bitmapData 中绘制另一个显示对象。
Ok, your question is not very clear, I suppose that you want to copy your content in a Bitmap.
If this is what you want to accomplish, just create a new bitmapData, draw your sprite in it and use it as a source of a Bitmap.
For example, when you finish to draw in your penSprite, you can copy it in a Bitmap like this:
Hope this is what you're looking for.
EDIT:
I see that you just add a comment in your question, saying that you want to draw "using bitmapData.draw". So, I think you are misunderstanding the use of that method. If you look in the documentation:
"Draws the source display object onto the bitmap image, using the Flash runtime vector renderer. "
So you basically use it to draw another display object in a bitmapData.