移动设备:嵌入图像以提高速度

发布于 2024-12-07 23:50:49 字数 73 浏览 1 评论 0原文

在移动 Air 应用程序中嵌入图像会加快绘制使用图像的 UI 的过程吗?

如何正确嵌入图像?

谢谢!

Would embedding images in mobile Air applications speed up the process of drawing the UI that uses images?

How does one properly embed the images?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情话难免假 2024-12-14 23:50:49

嵌入图像的优点是它包含在 SWF 文件中,并且比应用程序必须在运行时从远程位置加载图像时访问速度更快。但它也有一个缺点,即您的 SWF 文件比在运行时加载资源时要大。

嵌入过程非常简单,只需按照以下步骤操作即可:

  1. 将图像文件复制到应用程序的“src”文件夹中。 Flex 4将从那里获取这些文件。当然,您可以定义子文件夹以免混乱。

  2. 在你的类中定义如下例所示
    [嵌入(源=“728x90a.jpg”)]
    公共静态常量 imgData1:Class;

    728x90a.jpg是图像的文件名(我这里没有使用子文件夹)
    imgData1 是包含嵌入图像数据的对象!
    
  3. 在代码中的某个位置,将数据加载到可视组件中,如下例所示
    img1.source=imgData1;
    img1 是一个图像组件。

    <前><代码>包
    {
    公共类 TestProjectAssets
    {
    [嵌入(来源=“字体/MySuperDuperFont.otf”,
    fontFamily="SuperDuperFont",
    mimeType="应用程序/x-font",
    embedAsCFF="true")]
    私有 const SuperDuperFont:Class;

    [嵌入(源=“资产/mainMenu.png”)]
    公共静态常量mainMenuImg:类;
    }
    }

如果您需要处理大量资源,可以按照以下 3 个步骤进行操作:

Place them in an uncompressed zip archive

Embed the zip file as binary data:

[Embed(source = 'resources.zip', mimeType = 'application/octet-stream')]

Access the resources using [FZip][1]

如果您选择涉及加载外部文件的不同方法,请注意某些 Flash 游戏网站要求其托管的游戏包含在单个 swf 文件中。

The advantage of embedding an images is that it is included in the SWF file, and can be accessed faster than it can if the application has to load it from a remote location at run time. but it also have disadvantage that is your SWF file is larger than if you load the asset at run time.

The embed process is very simple, just follow to follow steps:

  1. copy your image files where the "src" folder is of your application. the Flex 4 will get these files from there. Of course you may define sub folders to do not mess up.

  2. In your class define like the example bellow
    [Embed (source="728x90a.jpg" )]
    public static const imgData1:Class;

    The 728x90a.jpg is the file name of the image (I didn't use sub folders here)
    The imgData1 is the object where contains the data of the embedded image!
    
  3. Somewhere in your code, load the data into a visual component, like the example bellow
    img1.source=imgData1;
    The img1 is an Image component.

    package
    {
       public class TestProjectAssets
       {
            [Embed(source="fonts/MySuperDuperFont.otf",
                fontFamily="SuperDuperFont",
                mimeType="application/x-font",
                embedAsCFF="true")]
            private const SuperDuperFont:Class;
    
            [Embed(source="assets/mainMenu.png")]
             public static const mainMenuImg:Class;
       }
    }
    

If you need to handle a large number of resources you can follow these 3 steps:

Place them in an uncompressed zip archive

Embed the zip file as binary data:

[Embed(source = 'resources.zip', mimeType = 'application/octet-stream')]

Access the resources using [FZip][1]

If you choose a different method that involves loading external files be aware that some flash game websites require the games they host to be contained within a single swf file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文