views:

812

answers:

2

Hello All, I'm having some issues while displaying a 'Base64' encoded image in my AIR application. I'm fetching an image, which is 'Base64' encoded string, in a XML through a web service. 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. My queries are: 1) After decoding the 'Base64' string, do I need to convert this to a PNG image using some PNG encoder? if so, then how can I use a PNGEncoder in my Adobe AIR HTML/Javascript application. is there any API or so? 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:

      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)

Please, help to solve this issue. I'll be really grateful for any of your suggestions. Thanks.

A: 

What <img> tag does this code produce?

I've been comparing it to an example which doesn't use Javascript, and since I'm not really familiar with JS, I can't spot any errors.

But the example I found closed the encoded string with " and followed it with ALT WIDTH and HEIGHT attributes. Does your code complete the tag properly?

I suppose I should be careful, in my ignorance, not to assume a complete correspondence between the 'id', 'class', 'src' and 'cat_id' elements and the final HTML. What does 'cat_id' mean?

pavium
Hi, Thanks for the reply.I forgot to mention that my code uses Mootools library, which allows to create such elements as, <img>, <div> etc. on the fly, with the help of 'Element' object, wherein you pass the 'tag' of the element you want to create and the rest of the attributes. In the code, mentioned above, its creating a <img> tag with its related attributes and 'cat_id' is a custom attribute to that tag for the application's need. Now, coming to your suggestion...well, thats exactly what I'd used, even in the code shown above, but it didn't work. Its Firebox supported feature.
Code.Warrior
Yes, I realised it's some sort of toolbox (and I should try those things myself) but what exactly is the img tag generated by it? If you view source, what do you see? The img element only understands a few attributes, although W3C told me about more than I knew previously.
pavium
The 'img' tag generated, for example, is as follows:<img id="category_header_img1" class="category_header_img" src="Category_Icons/1.png" cat_id="1">where source is a static image from a file.The attribute 'cat_id' has been provided for later manipulations and it doesn't any effect on the main 'img' tag.
Code.Warrior
I would focus my attention on the src attribute. What URL makes 'Category_icons/1.png' work in the address bar?
pavium
As I've mentioned in my comment, the source of the above example tag was from a local static image file(i.e. Category_Icons/1.png). In the question I'd asked earlier, the tag 'src' was referring to a 'base64' encoded string of that image which I'm fetching from a web server. I hope that clears the matter. Now the problem I'm facing is, that I'm not able to get the image displayed somehow. Although decoding of the fetched image is done without any error. An example(http://forums.adobe.com/thread/105556) on Flex show that I may need a PNGencoder to encode the image, in order to show it up.
Code.Warrior
But I don't know whether we've any such PNGEncoder for Javascript code or Adobe AIR has any api to provide this functionality?
Code.Warrior
Sorry, this probably shows the danger of trying to answer more than one question at a time. Yes, of course, there is no file in the case of a base64 encoded data string. It's in the string. I've only ever tried images encoded as base64 strings when I've been able to hard code the string IN the HTML. Here you're doing much more than that and we've reached the limits of my poor knowledge. Sorry to waste your time.
pavium
No don't worry. Thanks for your reply though.
Code.Warrior
+1  A: 

The data URL scheme isn't supported in AIR. What was the image before it was base64 encoded? 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. You should then be able to load it with an image tag.