-5

我有一个包含迷宫的字符串。
我需要将字符串转换为图像。到目前为止,我尝试了 base64encoder,但似乎 eclispse 不支持它。
有什么简单的解决方案吗?
我已经用谷歌搜索过了。

    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;
        }

我需要将 str 转换为图像。

    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;
    }

我试过了,但eclipse不接受内存流..

4

2 回答 2

2

尝试这个:

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

注意:android.util.Base64 自 Android API Level 8(即 Android 2.2.x 或更高版本)起已包含在内。对于旧版本,您必须从 Internet 下载 Base64 开源实现。

于 2013-05-20T14:06:21.023 回答
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

于 2013-05-20T14:08:30.973 回答