嵌入的位图图像可以是 JPEG、GIF 或 PNG 文件。您还可以嵌入由 Flash 生成的 SWF 文件中的位图元件。在上述每种情况下,MXML 编译器都会自动生成一个类,用于扩展 BitmapAsset 以显示嵌入的位图图像。
在写入 Flex 应用程序时,通常不必直接使用 BitmapAsset 类。例如,您可以通过编写如下内容来嵌入 GIF 文件并在 Image 控件中显示该图像:
<mx:Image id="logo" source="@Embed(source='Logo.gif')"/>
也可以使用 CSS 语法编写如下内容来将该图像用作应用程序的背景图像
<fx:Style>
@namespace mx "library://ns.adobe.com/flex/mx"
mx|Application {
backgroundImage: Embed(source="Logo.gif")
}
<fx:Style/>
而不必了解 MXML 编译器已为您创建了 BitmapAsset 的一个子类。
例子:
var dragImg:BitmapAsset = new BitmapAsset();
dragImg.bitmapData = new BitmapData(dragInitiator.width, dragInitiator.height);
//定义宽高
dragImg.bitmapData.draw(dragInitiator);
//直接画出源对象
|
draw(source:
IBitmapDrawable, matrix:
Matrix
= null, colorTransform:
flash.geom:ColorTransform
= null, blendMode:
String
= null, clipRect:
Rectangle
= null, smoothing:
Boolean
= false):
void
使用 Flash 运行时矢量渲染器在位图图像上绘制 source 显示对象。
|
被描绘的源对象必须是实现 IBitmapDrawable 接口的类,比如 Button
Button 的继承关系是:Button - UIComponent - FlexSprite - Sprite - DisplayObjectContainer - InteractiveObject - DisplayObject - EventDispatcher - Object
注意到中间有一个 DisplayObject 该类实现了IBitmapDrawable 接口,所以所有 UIComponent 的子类 都实现了IBitmapDrawable ,都可以被 draw 出来
本文介绍了在Flex开发中如何使用BitmapAsset类来处理和嵌入JPEG、GIF、PNG等图像文件,以及SWF中的位图元件。通过示例展示了在MXML和CSS中如何显示嵌入的图像,以及在代码中如何直接操作BitmapAsset的bitmapData属性。同时强调,由于DisplayObject类实现了IBitmapDrawable接口,因此UIComponent的子类可以被绘制。
3117

被折叠的 条评论
为什么被折叠?



