I tried this piece of code below to convert byte[] into System.Drawing.Image.
Tuple<int, int, int> t1 = DecimalToDegrees(Convert.ToDecimal(lat));
Tuple<int, int, int> t2 = DecimalToDegrees(Convert.ToDecimal(lon));
string ss = Math.Abs(t1.Item1) + "%C2%B0" + t1.Item2 + "'" + t1.Item3 + "%22N+"
+ Math.Abs(t2.Item1) + "%C2%B0" + t2.Item2 + "'" + t2.Item3 + "%22W/@";
string s1 = ss + t1 + "," + lt2 + ",14z/data=!4m5!3m4!1s0x0:0x0!8m2!3d" + t1 + "!4d" + t2;
s1 = "https://www.google.com/maps/place/" + s1;
System.Net.WebClient client = new System.Net.WebClient();
byte[] data = client.DownloadData(s1);
System.Drawing.Image chartImage = Base64ToImage(data);
....
public System.Drawing.Image Base64ToImage(byte[] imageBytes) {
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
ms.Write(imageBytes, 0, imageBytes.Length);
return System.Drawing.Image.FromStream(ms, true);
}
However, I got an exception "Parameter is not valid" at
System.Drawing.Image.FromStream(ms, true);
What's wrong in my code? Thanks if you can point out.
What I have tried:
Failed in converting byte[] into an image