-5

I have a string that contains a maze.
I need to convert the string to image. So far, I tried base64encoder but it seems eclispse doesn't support it.
Is there any simple solution for it?
I already googled it.

    public String arrayToString(String[][] stringarray)//converts arrays to string(maze array)
        {
            String str = "\n";

            for (int i = 0; i < stringarray.length; i++)
            {
                for(int j = 0; j<stringarray[i].length;j++)
                {
                    str+=stringarray[i][j];             
                }   
                str+="\n";
            }
            return str;
        }

I need to convert str to image.

    public Image Base64ToImage(String base64String)
    {
      // Convert Base64 String to byte[]
      byte[] imageBytes = Convert.FromBase64String(base64String);
      MemoryStream ms = new MemoryStream(imageBytes, 0, 
        imageBytes.length);

      // Convert byte[] to Image
      ms.Write(imageBytes, 0, imageBytes.length);
      Image image = Image.FromStream(ms, true);
      return image;
    }

I tried this but eclipse didn't accept memorystream..

aeb-dev
  • 313
  • 5
  • 16

2 Answers2

2

Try this:

    byte[] imageBytes=Base64.decode(imageString,Base64.NO_WRAP);
    InputStream in = new ByteArrayInputStream(imageBytes);
    Bitmap b = BitmapFactory.decodeStream(in);

note: android.util.Base64 has been included since Android API Level 8 (i.e. Android 2.2.x or later) For older version you have to download a Base64 an open source implementation from the internet.

Dory Zidon
  • 10,497
  • 2
  • 25
  • 39
  • what problems? eclipse is not your compiler.. – Dory Zidon May 20 '13 at 14:19
  • android.util.Base64 has been included since Android API Level 8 (i.e. Android 2.2.x or later), for older verison you have to download Base64 implementation off the internet.. – Dory Zidon May 20 '13 at 14:23
  • http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/DatatypeConverter.html#parseBase64Binary%28java.lang.String%29 it ships with Java, you can use it..comes from javax.xml.bind.DatatypeConverter so import and use. – Dory Zidon May 20 '13 at 14:42
0

Can you elaborate your question? As far as i understand you have to make some pixel manipulation based on the characters of your String. As i imagine that you are planing to create a pixel image, you can imagine that each character in the String can be mapped somehow to the pixel value.

For example take a look at this question :Buffered image pixel manipulation

Community
  • 1
  • 1
fGo
  • 1,146
  • 5
  • 11