2011-12-12 46 views
1

我正在用Flex 4.6和AIR構建應用程序。它將在Android和iPhone上發佈,但現在我正在Android設備上進行測試。Flex移動,切換屏幕時緩慢加載圖像

我已經有了基本的流程與不同的屏幕,甚至閃光燈組件。

但是,在屏幕之間切換時,即使在部署到實際設備時,我的所有s:Image對象也需要很長時間才能加載。很長一段時間,我的意思是半秒鐘左右。這通常不會很糟糕,但屏幕上的文本立即顯示,而所有圖像保持白色半秒,然後加載。

這只是一個AIR/Flex的東西?有沒有其他人跑過來,希望有解決方案?

+0

你打算怎麼樣加載圖片?他們是否嵌入在Flex應用程序中?或通過URL加載?或者是其他東西? – JeffryHouser

+0

我在代碼中使用image.source =「資源路徑」,否則我在設計器中使用源代碼按鈕,我相信它也會執行相同的操作。我會着手嵌入並找出這意味着什麼。 –

+0

我已經做了一些更多的嵌入測試(只需使用設計器中的複選框)。它看起來像加載速度更快。現在,如果我有重複的s:使用相同圖像源的圖像,如果我多次嵌入相同的資源,是否會堵塞內存? –

回答

1

如果將圖像嵌入到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作爲源。