读取JPG进入的BitmapData ActionScript 3中(JPG里面APK文件) [英] Reading JPG into BitmapData in ActionScript 3 (JPG is inside APK file)

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

问题描述

我使用的Adobe AIR使APK文件为我的Andr​​oid手机。里面的APK包有一个SWF文件,并​​在同一文件夹中的SWF文件中有一个名为图像子文件夹,其中包含image.jpg的。

我想读取image.jpg文件到程序在运行,但不能得到它的位置(该程序似乎并没有找到它。

下面就是我想:

  VAR装载机:装载机=新的Loader();
loader.contentLoaderInfo.addEventListener(引发Event.COMPLETE,的onComplete);
loader.load(新的URLRequest(图像/ image.jpg文件));
而(位图数据== NULL){} //等到装
返回的位图数据;
 

本的onComplete功能使设置的位图数据领域。但是,完整的事件从未发生过这样的while循环永远存在。

我也曾尝试:

  loader.load(新的URLRequest(/图像/ image.jpg文件));
loader.load(新的URLRequest(应用程序:/images/image.jpg));
loader.load(新的URLRequest(应用程序存储:/images/image.jpg));
loader.load(新的URLRequest(文件:/images/image.jpg));
 

没有了它的工作原理。

我不能得到这个尝试没有APK文件时,当时只有运行时生成的SWF文件的工作,即使(图像子文件夹是在同一文件夹中的SWF文件)。

我不能嵌入JPG到SWF文件本身,因为我需要有大量的图像文件和Flash CS6这么大的SWF文件(读取图像外部也意味着一大堆,当内存不足更少的编译时间)。

任何想法?我怎样才能把外部JPG文件到的BitmapData?请记住,图像不是APK文件之外,它被打包在里面。

注:我也会的东西导出到的iOS IPA包后,因此要在那里工作,以及


修改,因为我不能自我的答案,由于我的名声。

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

所以这是不可能让一个线程睡眠(等待)的图像加载。相反,我要的叹息的改写了大量的code,这样的事情都停止,继续当的onComplete函数被调用。

这件事,我才真正尝试过的作品,但不能完全由于while循环:

  loader.load(新的URLRequest(应用程序:/images/image.jpg));
 

解决方案

如果我没记错的话,你应该能够做到这一点是这样的:

  loader.load(新的URLRequest(新文件(应用程序:/images/image.jpg)的URL));
 

由于我们正在使用的文件类,上面会不会在Flash Player只是在iOS和Android上运行。

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.

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.

Here's what I'm trying:

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;

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

I have also tried:

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"));

None of it works.

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).

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).

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.

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


Edit because I can't self-answer due to my reputation.

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

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.

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));

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

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

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