《Image Effects 》第一章学习笔记(2)
2009-12-14 15:35
246 查看
现在有一些时间,继续把之前那本英语书As图像处理写一下记录。在Image Effect 第一章里面是主要介绍几种Api的不同功能,并演示了不同API的的做法。现在开始,粘贴上第一个书里面的编码。
1。绘制一条直线,主要使用的API 包括moveTo 和 lineTo 、lineStyle,clear这四个函数。
moveTo 和lineTo 都有两个参数,而两个参数都是记录坐标点。(x,y)
moveTo(x:Number,y:Number):void;
moveTo这个函数就像一支笔,一开始绘制画面的落脚点。
lineTo(x:Number,y:Number):void// 绘制一条直线,从笔的当前点,到一个新的点。
lineStyle(.....)这个函数,可以设置线条的样式。包括颜色,透明度,粗细等方式。
![](http://p.blog.csdn.net/images/p_blog_csdn_net/hero82748274/EntryImages/20091214/linestyle.jpg)
clear():void 清除画面
在这本书第一个程序当中,我们可以使用鼠标来绘制不同的线条。这些线条会产生不同的颜色。当鼠标按下去的时候,就像一支笔那样进行绘制。当放开鼠标的时候,线条就会结束。通过简单鼠标交互。就能编写出一个画线的程序了。
下面是源代码:可以到
http://www.friendsofed.com/downloads.html 这个网站下载到这本书给出的内容。
下面就是一副使用绘制线条画出的效果。不是直接的结果。通过这个程序,我们主要是了解以上四种的API的功能。组合我们希望的程序。
![](http://p.blog.csdn.net/images/p_blog_csdn_net/hero82748274/EntryImages/20091214/线条ss.jpg)
下面接下去,继续探讨第一章的内容。
1。绘制一条直线,主要使用的API 包括moveTo 和 lineTo 、lineStyle,clear这四个函数。
moveTo 和lineTo 都有两个参数,而两个参数都是记录坐标点。(x,y)
moveTo(x:Number,y:Number):void;
moveTo这个函数就像一支笔,一开始绘制画面的落脚点。
lineTo(x:Number,y:Number):void// 绘制一条直线,从笔的当前点,到一个新的点。
lineStyle(.....)这个函数,可以设置线条的样式。包括颜色,透明度,粗细等方式。
![](http://p.blog.csdn.net/images/p_blog_csdn_net/hero82748274/EntryImages/20091214/linestyle.jpg)
clear():void 清除画面
在这本书第一个程序当中,我们可以使用鼠标来绘制不同的线条。这些线条会产生不同的颜色。当鼠标按下去的时候,就像一支笔那样进行绘制。当放开鼠标的时候,线条就会结束。通过简单鼠标交互。就能编写出一个画线的程序了。
下面是源代码:可以到
http://www.friendsofed.com/downloads.html 这个网站下载到这本书给出的内容。
package { import flash.display.Shape; import flash.display.Sprite; import flash.events.MouseEvent; import flash.geom.Point; [SWF(width=550, height=400, backgroundColor=0xFFFFFF)] /** * Demonstrates how to draw straight lines with the drawing API. */ public class DrawingStraightLines extends Sprite { private var _currentShape:Shape; private var _color:uint; private var _startPosition:Point; /** * Constructor. Sets up listeners for mouse events. */ // 在构造函数里面,建立起鼠标事件的监听 public function DrawingStraightLines() { stage.addEventListener(MouseEvent.MOUSE_DOWN, onStageMouseDown); stage.addEventListener(MouseEvent.MOUSE_UP, onStageMouseUp); } /** * Draws a line from the start position to the current mouse position. */ //绘制直线 private function drawLine():void { _currentShape.graphics.clear(); _currentShape.graphics.lineStyle(3, _color); _currentShape.graphics.moveTo(_startPosition.x, _startPosition.y); _currentShape.graphics.lineTo(stage.mouseX, stage.mouseY); } /** * Handler for when the stage is clicked. This creates a new shape for the current line, * saves the starting posiiton and sets up a listener for when the mouse moves. * * @param event Event dispatched by the stage. */ //鼠标按下的时候记录该鼠标的点和随机设置线条的颜色 private function onStageMouseDown(event:MouseEvent):void { _color = Math.random()*0xFFFFFF; _currentShape = new Shape(); addChild(_currentShape); _startPosition = new Point(stage.mouseX, stage.mouseY); stage.addEventListener(MouseEvent.MOUSE_MOVE, onStageMouseMove); } /** * Handler for when the mouse is released. This removes the listener for when the mouse moves. * * @param event Event dispatched by the stage. */ //鼠标不按下的时候,取消鼠标移动的监听 private function onStageMouseUp(event:MouseEvent):void { stage.removeEventListener(MouseEvent.MOUSE_MOVE, onStageMouseMove); } /** * Handler for when the mouse moves. This updates the drawn line based on the current mouse position. * * @param event Event dipsatched by the stage. */ //鼠标移动的时候进行拖动绘制曲线 private function onStageMouseMove(event:MouseEvent):void { drawLine(); event.updateAfterEvent(); } } }
下面就是一副使用绘制线条画出的效果。不是直接的结果。通过这个程序,我们主要是了解以上四种的API的功能。组合我们希望的程序。
![](http://p.blog.csdn.net/images/p_blog_csdn_net/hero82748274/EntryImages/20091214/线条ss.jpg)
下面接下去,继续探讨第一章的内容。
相关文章推荐
- 《Image Effects 》第一章学习笔记(1)
- 《Image Effects 》第一章学习笔记(3)
- 《Image Effects 》第一章学习笔记(2)
- 《Image Effects 》第一章学习笔记(3)
- 《Image Effects 》第一章学习笔记(1)
- OpenCV学习笔记16 OpenCV图像处理模块ImgProc Module. Image Processing(九)
- 【jQuery】jQuery官方基本教程的学习笔记3-动画效果Effects
- [蛙蛙推荐]SICP第一章学习笔记-编程入门
- 【php学习】PHP 入门经典第一章笔记
- C++primer第五版【学习笔记】——第一章
- 数据库系统概念 第一章 学习笔记
- SICP学习笔记 - 第一章 (1.2)
- SICP学习笔记 - 第一章 (1.3)
- Scala第一章学习笔记
- ImageView、Gallery以及GridView学习笔记
- 汇编语言第一章学习笔记和测试题
- ASP.NET本质论第一章网站应用程序学习笔记1
- ReactNative 学习笔记 Component - Image,Picker
- 【C++学习01】《Essential C++》第一章(Basic C++ Programming)笔记
- Universal Image Loader 学习笔记-图片加载