添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hello,

we have an xamarin android app who call an API who send a QRCode as a string
Look the print screen i join, here is it what i receive after the call to the api ..

Now i would like to transform this string into a image but i can't ..

Someone has idea how to transform string into image ?!
105578-qrcodequestion.png

thanks for all

Hi @cristopheB

I'm assuming that your API has returned the image, and then converted the image to Base64 (a common way of passing images around as text). If this assumption is wrong, please clarify your case!

If my assumption is correct, then having received the image as text in a Base64 string, you can then decode it using:

   var byteArray = Convert.FromBase64String(base64text);  

then what you have is the same byte array as if you had opened the image file from disk and converted it to a byte array.

So in this case you just need to convert it to a Stream:

   Stream stream = new MemoryStream(byteArray);  

At this point, just pass the Stream to your image, I don't have the Xamarin.Android code at hand, but to illustrate the process using the Xamarin.Forms equivalent:

   var byteArray = Convert.FromBase64String(base64text);  
   Stream stream = new MemoryStream(byteArray);  
   var imageSource = ImageSource.FromStream(()=>stream);  
   MyImage.Source = imageSource;  
											

Hello @Harrison of The North ,

thanks a lot for all explication and code that's nice

well, the problem was the encoding of the image we follow what you said and now it's perfect !
thanks