Tejas Harne
Tejas Harne

Reputation: 1

Regarding conversion of image-to-base64 string in TouchDevelop

I am getting an image (encoded in base64 string format) from a server. This base64-encoded string has to be converted back to image. I am doing in two steps:

  1. Convert the base64 encoded string into a buffer - Using bits -> string to buffer(string,"base64")

  2. Write the buffer into a picture (of same dimensions) - Using Picture -> write buffer(buffer) and then I'm displaying the picture.

The base64 string from the server (whole string):

iVBORw0KGgoAAAANSUhEUgAAAJEAAAAeCAYAAAAsPvwuAAAAmUlEQVR42u3SQQoAIQgAwL7h/x+6sQsLHcqCPI7QITGNmvYsIiK+leX+/ZjPcifnsnvs5pzW3PaunLGrm/W6eZPqv3yjQQQRRBBBBBFEEEEEEUQQQQQRRBBBBBFEEEEEEUQQQQQRRBBBBBFEEEEEEUQQQQQRRBBBBBFEEEEEEUQQQQQRRBBBBBFEEEEEEUQQQQQRRBBBVIuoAwQlLkAhgPjNAAAAAElFTkSuQmCC

The problem is: I am not getting the desired image when I display it on the wall. It just shows a very small image.

So I tried finding what string TouchDevelop expected in bits -> string to buffer(string,"base64") method.

  1. I obtained the original image from online converter (http://www.motobit.com/util/base64-decoder-encoder.asp) supplying the same string as obtained from the server. This image was correct.
  2. Then I did the reverse process of what I described above – Converting an image into base64 string. This, I did by using Picture to buffer(Picture) and then buffer to string(“base64“) and displayed the base64 string as generated by TouchDevelop for the same image.

The base64 string I got from TouchDevelop (just a small part of actual string - Actual string size-23,300 chars):

////////////////////////////////GRkZ/xkZGf////////////////8ZGRn/GRkZ////////////GRkZ/xkZGf8ZGRn/GRkZ//////8ZGRn/GRkZ/xkZGf8ZGRn//////xkZGf8ZGRn///////////8ZGRn/GRkZ/xkZGf8ZGRn//////xkZGf8ZGRn//////////////////////xkZGf8ZGRn//////xkZGf8ZGRn//////xkZGf8ZGRn/GRkZ/xkZGf///////////xkZGf8ZGRn//////xkZGf8ZGRn/GRkZ/xkZGf//////////////////////GRkZ/xkZGf//////GRkZ/xkZGf//////GRkZ/xkZGf8ZGRn/GRkZ////////////GRkZ/xkZGf8ZGRn/GRkZ//////8ZGRn/GRkZ/xkZGf8ZGRn//////////////////////xkZGf8ZGRn//////xkZGf8ZGRn//////xkZGf8ZGRn///////////8ZGRn/GRkZ//////8ZGRn/GRkZ//////////////////////8ZGRn/GRkZ/xkZGf8ZGRn//////xkZGf8ZGRn//////xkZGf8ZGRn/GRkZ/xkZGf///////////xkZGf8ZGRn////////////////……

As you might have noticed, the base64 string from the server and the base64 string what TouchDevelop expects to show the correct image have a huge difference. And this is resulting into displaying of an incorrect image. I am stuck in this problem for a few days. Is there a bug? If not, can anyone help me with this problem?

Upvotes: 0

Views: 52

Answers (0)

Related Questions