如果将图像嵌入到Flex应用程序中,图像的加载速度会更快。 More info on that here。这背后的代码应该是这样的:如果你需要使用相同的图像
<s:Image id="myImageRaw" source="{imgCls}"/>
[从文档复制代码]
:
[Embed(source="logo.gif")]
[Bindable]
public var imgCls:Class;
然后你可以使用这个类像这样多次,你应该看看使用BitMapImage类;并克隆第一个图像的bitMapData。这是一个快速实用工具类I“Borrowed and modified”,用于从精灵获取BitMapData,反之亦然。 [Flex的Image类类扩展精灵,所以你应该能够在发送图像作为输入]
package com.natejc.utils.display
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Sprite;
// **********************************************************************************
// **********************************************************************************
// borrowed from http://www.natejc.com/source/com/natejc/utils/display/DisplayConverter.as
/**
* Provides convenience conversion methods for Sprites and Bitmaps.
*
* Open source. Free to use. Licensed under the MIT License.
*
* @author Nate Chatellier
* @see http://blog.natejc.com
*/
public class DisplayConverter
{
// **********************************************************************************
/**
* Constructs the DisplayConverter object.
*/
public function DisplayConverter()
{
trace("DisplayConverter is a static class and should not be instantiated");
} // END CONSTRUCTOR
// **********************************************************************************
/**
* Converts a Bitmap to a Sprite.
*
* @param bitmap The Bitmap that should be converted.
* @param smoothing Whether or not the bitmap is smoothed when scaled.
* @return The converted Sprite object.
*
* @see http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Bitmap.html#smoothing
*/
public static function bitmapToSprite(bitmap:Bitmap, smoothing:Boolean = false):Sprite
{
var sprite:Sprite = new Sprite();
sprite.addChild(new Bitmap(bitmap.bitmapData.clone(), "auto", smoothing));
return sprite;
} // END FUNCTION bitmapToSprite
// **********************************************************************************
/**
* Converts a Sprite to a Bitmap.
*
* @param sprite The Sprite that should be converted.
* @param smoothing Whether or not the bitmap is smoothed when scaled.
* @return The converted Bitmap object.
*
* @see http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html#draw()
*/
public static function spriteToBitmap(sprite:Sprite, smoothing:Boolean = false):Bitmap
{
var bitmapData:BitmapData = new BitmapData(sprite.width, sprite.height, true, 0x00FFFFFF);
bitmapData.draw(sprite);
return new Bitmap(bitmapData, "auto", smoothing);
} // END FUNCTION spriteToBitmap
/**
* JH DotComIT added 11/19/2011
* Converts a Sprite to a BitmapData.
*
* @param sprite The Sprite that should be converted.
* @return The converted Bitmap object.
*
* @see http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html#draw()
*/
public static function spriteToBitmapData(sprite:Sprite):BitmapData
{
var bitmapData:BitmapData = new BitmapData(sprite.width, sprite.height, true, 0x00FFFFFF);
bitmapData.draw(sprite);
return bitmapData;
} // END FUNCTION spriteToBitmapData
/**
* Converts BitmapData to a Sprite.
*
* @param bitmap The Bitmap that should be converted.
* @param smoothing Whether or not the bitmap is smoothed when scaled.
* @return The converted Sprite object.
*
* @see http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Bitmap.html#smoothing
*/
public static function bitmapDataToSprite(bitmapData:BitmapData, smoothing:Boolean = false):Sprite
{
var sprite:Sprite = new Sprite();
sprite.addChild(new Bitmap(bitmapData.clone(), "auto", smoothing));
return sprite;
} // END FUNCTION bitmapToSprite
// **********************************************************************************
// **********************************************************************************
} // END CLASS DisplayConverter
} // END PACKAGE
一旦你的位图数据可以调用clone得到它的拷贝,创造的多个实例相同的图像。 [做一些关于blitting的研究;游戏开发者使用的技术]。 Spark Image标签也将接受BitMapData作为源。
你打算怎么样加载图片?他们是否嵌入在Flex应用程序中?或通过URL加载?或者是其他东西? – JeffryHouser
我在代码中使用image.source =“资源路径”,否则我在设计器中使用源代码按钮,我相信它也会执行相同的操作。我会着手嵌入并找出这意味着什么。 –
我已经做了一些更多的嵌入测试(只需使用设计器中的复选框)。它看起来像加载速度更快。现在,如果我有重复的s:使用相同图像源的图像,如果我多次嵌入相同的资源,是否会堵塞内存? –