6 Replies Latest reply on Mar 29, 2011 3:21 PM by mick.powell

    Image from string




      this may sound like a strange question but i'm not really sure how to tackle it.


      When using the image class, i'm pretty sure i can do source="http://url/image.png" but i have an additional layer of complexity in that the data on the website is base64encoded


      i.e. http://url/path/to/image.php results in a base64encoded string


      i can decode this string but then i'm having trouble taking this string and setting it as the source for an image.


      Any ideas on how i can do that? This is for an application running on a mobile device using the hero sdk. If that helps in any way.


      thank you very much.



        • 1. Re: Image from string
          UbuntuPenguin Level 4

          There's LOTS of information online on converting a Base64 string into an image.  If

          I remember correctly, the flexlibs library even has a class that does that.

          1 person found this helpful
          • 2. Re: Image from string

            I was about to answer the same way but I think his issue is that he's getting a reference to an image not the bytearray for the image itself. I'm not sure why he'd have trouble with setting the reference (http://somesite.com/path/to/image/jpg) though.

            • 3. Re: Image from string
              anoopbhat Level 1

              Hi Guys.


              wow quick replies! love it! Thank you.


              So part of my issue is that the server (an API) returns the data this way when you ask for it


              if the url is http://server/path/to/image.php









              it's annoying but there isn't much i can do about that so i have to save the text, strip out the html tags and then decode it.


              but it seems that i may not need to decode it and can assign it as is to an image?


              i know that the Base64decoder class has a toByteArray() function to which i added .toString()


              maybe i need to omit the .toString() entirely.


              Thank you to both. it never occurred to me to look online for this particular issue.

              • 4. Re: Image from string
                Codeflayer Level 1

                Yeah, if you're getting the raw image data as a bytearray just assign that as the source and you should be golden.

                1 person found this helpful
                • 5. Re: Image from string
                  anoopbhat Level 1

                  Do i need to do more than just


                  i.source = resba;  ?


                  here is what i'm doing in my function imagehandler



                  // what to do when the image is downloaded.

                  var res:String = event.result.toString();

                  var decoder:Base64Decoder = new Base64Decoder;

                  var resba:ByteArray;


                  trace("IMAGE RESULT: " + res);



                  var i:Image = new Image;


                  res = res.replace(/<[\/]html>/, "");

                  trace("IMAGE RESULT 2: " + res);




                  resba = decoder.toByteArray();


                  trace("IMAGE RESULT 3: " + resba);


                  i.source = resba;



                  • 6. Re: Image from string
                    mick.powell Level 1

                    I've seen this way of working this and its one that we use in a project


                    var loader:Loader = new Loader();




                    Where resba is your decoded byteArray