Im sending in data through post and get a png back in the response. Convert it to base64 so i dont have to save the file. The image is a qr code and it seems to suffer from some quality loss since iPhones cant seem to scan it, androids are fine. Ive tried setting some encoding settings but that didnt do anything.
The data seems to be read correctly but im guessing that the center logo is to choppy to be read by the iphones. Any ideas?
Public Sub updateSwish()
Dim getPrice As Integer = 100
Try
Dim data As String = "{'format':'png','size':300,'message':{'value':'test','editable':false},'amount':{'value':" + Total.ToString + ",'editable':false},'payee':{'value':'123456789','editable':false}}"
Dim json As JObject = JObject.Parse(data)
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Dim s As HttpWebRequest = HttpWebRequest.Create("https://mpc.getswish.net/qrg-swish/api/v1/prefilled")
Dim enc As UTF8Encoding
Dim postdata As String
Dim postdatabytes As Byte()
enc = New System.Text.UTF8Encoding()
postdata = json.ToString
postdatabytes = enc.GetBytes(postdata)
s.Method = "POST"
s.ContentType = "application/json"
s.ContentLength = postdatabytes.Length
Dim myresponse As HttpWebResponse
Dim returnval As System.Drawing.Image
Using stream = s.GetRequestStream()
stream.Write(postdatabytes, 0, postdatabytes.Length)
End Using
Using mStream As New MemoryStream()
Dim imgByte As Byte()
myresponse = CType(s.GetResponse(), HttpWebResponse)
returnval = Image.FromStream(myresponse.GetResponseStream(), True, True)
returnval.Save(mStream, returnval.RawFormat)
imgByte = mStream.ToArray()
Dim base64String As String = Convert.ToBase64String(imgByte, 0, imgByte.Length)
imgSwish.Src = "data:image/png;base64," & base64String
End Using
Catch ex As Exception
Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), "ex", "alert('" + ex.Message + "');", True)
End Try
End Sub
EDIT: Turns out that the provider had a v2 coming out due to problems from iphones. The code was fine all along, and the base64 conversion worked as it should. I tried doing the same project i PHP and got the same result.