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.

 

Sure! Here's an example program that meets your requirements: ```java import java.awt.*; public class NameDrawing extends Frame { public NameDrawing() { super("Graphical Representation of My Name"); setSize(500, 300); setVisible(true); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent we) { dispose(); } }); } public void paint(Graphics g) { // Draw colored rectangles g.setColor(Color.red); g.fillRect(50, 50, 100, 100); g.setColor(Color.green); g.fillRect(200, 50, 100, 100); g.setColor(Color.blue); g.fillRect(350, 50, 100, 100); // Draw hanzi for 程 g.setColor(Color.white); g.drawLine(75, 75, 125, 75); g.drawLine(75, 75, 75, 125); g.drawLine(75, 125, 125, 125); g.drawLine(125, 75, 125, 125); g.drawLine(75, 100, 125, 100); // Draw hanzi for 嘉 g.drawLine(225, 75, 275, 75); g.drawLine(225, 75, 225, 125); g.drawLine(225, 125, 275, 125); g.drawLine(275, 75, 275, 125); g.drawLine(225, 100, 275, 100); g.drawLine(250, 75, 250, 125); // Draw hanzi for 一 g.drawLine(375, 75, 425, 75); g.drawLine(375, 125, 425, 125); g.drawLine(400, 75, 400, 125); } public static void main(String[] args) { new NameDrawing(); } } ``` This program creates a window using AWT, with colored rectangles and hanzi for each character of my name drawn using simple lines. The `paint()` method is overridden to handle the custom drawing. The rectangles are filled with different colors, and each hanzi is drawn using only lines. You could further improve this program by organizing the drawing code into separate methods or classes, using variables to define the rectangle sizes and positions, and adding more characters to the name if desired.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值