About the drawing

About the drawing

1.       Flex绘图可以使用flash.display.Graphics绘图。

Graphics 类拥有一系列的函数创建向量图形。Display 对象可以支持SpriteShape对象的绘图。这些类含有Graphics类型的graphics属性。例如函数drawRect()(直角矩形),drawRoundRect()(圆角矩形), drawCircle()(圆形), drawEllipse()(椭圆)

但是Graphics对象不能够直接从ActionScript语言中直接实例化,直接使用new尝试实例化,会抛出异常。并且Graphics类是final的,不能够被继承。

SpriteShape中都含有此属性。

例如代码:

            var child:Shape = new Shape();

            child.graphics.beginFill(bgColor);

            child.graphics.lineStyle(borderSize, borderColor);

            child.graphics.drawRoundRect(0, 0, size, size, cornerRadius);

            child.graphics.endFill();

            addChild(child);

这段代码需要写在从DisplayObjectContainer继承的类中。

 

2.       上面是直接使用包含Graphics对象的类进行绘制的,而包含graphics对象是从Shape或者Sprite继承而来。还有一种方法,可以将图绘制到Bitmap上。

这种方法步骤如下:

(a)     新建BitmapData对象

(b)     调用BitmapDate. draw(source:IBitmapDrawable, matrix:Matrix = null, colorTransform:flash.geom:ColorTransform = null, blendMode:String = null, clipRect:Rectangle = null, smoothing:Boolean = false):void

在此函数中,实现IBitmapDrawable接口的类比较多,包括TextFieldGraphics

(c)     新建Bitmap对象,用BitmapData进行初始化

Bitmap(bitmapData:BitmapData = null, pixelSnapping:String = "auto", smoothing:Boolean = false)

(d)     通过DisplayObjectContainer及其子类调用addChild(child:DisplayObject):DisplayObjectBitmap添加该Bitmap对象。

优缺点:

优点:使用Bitmap比较灵活,占用资源小,速度快。

缺点:使用Bitmap有大小限制。因此千万注意,否则会出现运行时异常。

In AIR 1.5 and Flash Player 10, the maximum size for a BitmapData object is 8,191 pixels in width or height, and the total number of pixels cannot exceed 16,777,215 pixels. (So, if a BitmapData object is 8,191 pixels wide, it can only be 2,048 pixels high.) In Flash Player 9 and earlier and AIR 1.1 and earlier, the limitation is 2,880 pixels in height and 2,880 pixels in width. If you specify a width or height value that is greater than 2880, a new instance is not created.

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值