About the drawing

來源:互聯網
上載者:User

 

  1. Flex繪圖可以使用flash.display.Graphics繪圖。

Graphics 類擁有一系列的函數建立向量圖形。Display 對象可以支援Sprite和Shape對象的繪圖。這些類含有Graphics類型的graphics屬性。例如函數drawRect()(直角矩形),drawRoundRect()(圓角矩形), drawCircle()(圓形), drawEllipse()(橢圓)。

但是Graphics對象不能夠直接從ActionScript語言中直接執行個體化,直接使用new嘗試執行個體化,會拋出異常。並且Graphics類是final的,不能夠被繼承。

在Sprite和Shape中都含有此屬性。

例如代碼:

            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繼承的類中。

 

  1. 上面是直接使用包含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介面的類比較多,包括TextField,Graphics等

(c)    
建立Bitmap對象,用BitmapData進行初始化

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

(d)    
通過DisplayObjectContainer及其子類調用addChild(child:DisplayObject):DisplayObject將Bitmap添加該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.

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.