简体   繁体   English

如何使用Javascript / HTML在Adobe AIR应用程序中显示“ Base64”编码的图像

[英]How to display 'Base64' encoded image in Adobe AIR application using Javascript/HTML

I'm having some issues while displaying a 'Base64' encoded image in my AIR application. 在AIR应用程序中显示“ Base64”编码的图像时遇到一些问题。 I'm fetching an image, which is 'Base64' encoded string, in a XML through a web service. 我正在通过Web服务以XML格式获取图像,该图像是“ Base64”编码的字符串。 At application side I'm able to decode it, but its not been able to display the image on the fly. 在应用程序端,我可以对其进行解码,但是它无法即时显示图像。 A little search on Google gave me various result, but not pertaining to my problem, because most of them are related to Flex. 在Google上稍作搜索即可获得各种结果,但与我的问题无关,因为它们大多数与Flex有关。 My queries are: 1) After decoding the 'Base64' string, do I need to convert this to a PNG image using some PNG encoder? 我的查询是:1)解码“ Base64”字符串后,是否需要使用某些PNG编码器将其转换为PNG图像? if so, then how can I use a PNGEncoder in my Adobe AIR HTML/Javascript application. 如果是这样,那么如何在我的Adobe AIR HTML / Javascript应用程序中使用PNGEncoder。 is there any API or so? 有没有API左右? 2) Since the image I'm fetching from the web server is an icon, I'm setting it as a 'src' value for the element which I'm creating dynamically as follows: 2)由于我要从网络服务器上获取的图像是一个图标,因此将其设置为要动态创建的元素的“ src”值,如下所示:

            var category_header_img = new Element('img', 
        {
            'id': 'category_header_img' + this.SelectedCategoryID,
            'class': 'category_header_img',
            'src': 'data:image/png;base64,'+categoryIconBytes,
            'cat_id': this.SelectedCategoryID

        });

I'd found this solution, 'src': 'data:image/png;base64,'+categoryIconBytes somewhere which tried to use but it didn't work.(where, categoryIconBytes is the 'Base64' encoded string) 我找到了这个解决方案'src': 'data:image/png;base64,'+categoryIconBytes在试图使用的地方,但是没有用(其中categoryIconBytes是'Base64'编码的字符串)

Please, help to solve this issue. 请帮助解决此问题。 I'll be really grateful for any of your suggestions. 我真的很感谢您的任何建议。 Thanks. 谢谢。

The data URL scheme isn't supported in AIR. AIR不支持数据URL方案。 What was the image before it was base64 encoded? 进行base64编码之前的图像是什么? If it is already a PNG, then all you need to do is reverse the base 64 encoding and save it locally to a temporary file. 如果已经是PNG,那么您要做的就是反转base 64编码并将其本地保存到一个临时文件中。 You should then be able to load it with an image tag. 然后,您应该可以使用图像标签加载它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM