Link to home
Start Free TrialLog in
Avatar of WangProducts
WangProducts

asked on

Display a base64 encoded image in flash?


Hi all,

I am using a service on the net which provides dynamic map images. The idea is basically that you make a "GET" request to the mapping server providing them with co-ordinates of what area of the map would you like to view and the scale to display, and then they send you back XML which has details of the area inside it - and most importantly, a map image which has been dynamically generated for you (can be any format you choose including jpg, gif, png etc).

The image is inside the XML in Base64Binary encoded format (raw image data), for example (truncated this example a lot):

<Image>/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODw...etc</Image>

You are then supposed to base64 decode this, and that will give you your map image.

I have flash/actionscript code that will make a GET request to their server and retrieve the XML. It then goes through the XML and obtains the data between the <Image></Image> tags and puts it into a myImage variable.

My question is...what would I then need to do in flash/actionscript to get this raw image data into something displayed on the screen to the user  as a proper image? Is there any way to create a new image on the fly using raw image data?

The only thing I can think of is that I would make the actionscript write the data out to the hard drive as "newfile.jpg" and then make it read the image back in and display it from there...but I am wondering if there is a better way since a lot of people will be using this and I would like to avoid creating tons of temporary image files on the hard drive.

Does anyone know how to solve this problem (or alternatively, can provide me code on how to write the image data out to a file on the hard drive, and then make flash display the newly created image file on the fly?)

Thank you in advance!
Avatar of WangProducts
WangProducts

ASKER


i'm surprised no-one answered this :) I asked on other flash forums and everyone was eager to help with a genuinely advanced question.

The answer is - this can't be done on the fly in flash/actionscript...however PHP can do it using something similar to:

Therefore, you can put a php script up that grabs the base64 image, decodes it, and displays is - then make flash/actionscript read it in on the fly using loadMovie();

:)
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial