在 ActionScript 3 中将 JPG 读入 BitmapData(JPG 在 APK 文件中) [英] Reading JPG into BitmapData in ActionScript 3 (JPG is inside APK file)

查看:19
本文介绍了在 ActionScript 3 中将 JPG 读入 BitmapData(JPG 在 APK 文件中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Adob​​e AIR 为我的 Android 手机制作 APK 文件.在 APK 包内有一个 SWF 文件,在与 SWF 文件相同的文件夹中有一个名为images"的子文件夹,其中包含 image.jpg.

I'm using Adobe AIR to make APK file for my Android phone. Inside the APK package there is a SWF file and in the same folder as the SWF file there is a subfolder named "images", which contains image.jpg.

我试图在运行时将该 image.jpg 读入程序,但无法获取它的位置(程序似乎没有找到它.

I'm trying to read that image.jpg into the program at runtime but can't get the location of it (the program doesn't seem to find it.

这是我正在尝试的:

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("images/image.jpg"));
while (bitmapData==null) {}  //wait until loaded
return bitmapData;

onComplete 函数 puts 设置了 bitmapData 字段.但是,COMPLETE 事件永远不会发生,因此 while 循环永远不会存在.

The onComplete-function puts sets the bitmapData field. However, the COMPLETE event never happens so the while loop never exists.

我也试过:

loader.load(new URLRequest("/images/image.jpg"));
loader.load(new URLRequest("app:/images/image.jpg"));
loader.load(new URLRequest("app-storage:/images/image.jpg"));
loader.load(new URLRequest("file:/images/image.jpg"));

都没有效果.

即使在没有 APK 文件的情况下尝试,仅运行生成的 SWF 文件(图像子文件夹与 SWF 文件位于同一文件夹中)时,我也无法使其工作.

I can't get this to work even when trying without the APK file, when only running the SWF file that is generated (the images subfolder is in the same folder as the SWF file).

我无法将 JPG 嵌入 SWF 文件本身,因为我需要有很多图像文件,而 Flash CS6 在制作如此大的 SWF 文件时会耗尽内存(从外部读取图像也意味着很多更少的编译时间).

I can't embed the JPG into the SWF file itself because I need to have a lot of image files and Flash CS6 runs out of memory when making such a big SWF file (reading the images externally would also mean a whole lot less compilation time).

有什么想法吗?如何将外部 JPG 文件放入 BitmapData?记住图片不在APK文件之外,它是打包在里面的.

Any ideas? How can I get put the external JPG file into BitmapData? Remember that the image is not outside of the APK file, it is packaged inside it.

注意:稍后我还将把这个东西导出到 iOS ipa 包中,所以它也必须在那里工作.

Note: I'll also export the thing into a iOS ipa package later so it have to work there as well.

编辑,因为我的名声让我无法自行回答.

Strille 让我意识到 ActionScript 虚拟机是单线程的.

Strille made me realize that the ActionScript Virtual Machine is single-threaded.

因此不可能让线程休眠(等待)加载图像.相反,我不得不叹气重写大量代码,以便在调用 onComplete 函数时停止并继续.

So it's impossible to make a thread sleep (wait) for an image being loaded. Instead I have to sigh rewrite a lot of code so that things are halted and continues when the onComplete function is called.

我之前尝试过的这个东西确实有效,但由于while循环而无法完成:

This thing that I tried before actually works but couldn't complete due to the while loop:

loader.load(new URLRequest("app:/images/image.jpg"));

推荐答案

如果我没记错的话,你应该可以这样做:

If I remember correctly, you should be able to do it like this:

loader.load(new URLRequest(new File("app:/images/image.jpg").url));

由于我们使用的是 File 类,因此上述内容不会在 Flash Player 中运行,只能在 iOS 或 Android 上运行.

Since we're using the File class, the above will not run in the Flash Player, just on iOS or Android.

这篇关于在 ActionScript 3 中将 JPG 读入 BitmapData(JPG 在 APK 文件中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆