private ImageSettings GetLatestImageInfo() { ImageSettings iSettings = null; try { using (var wc = new WebClient()) { var json = wc.DownloadString("http://himawari8-dl.nict.go.jp/himawari8/img/D531106/latest.json?" + Guid.NewGuid()); var iInfo = JsonConvert.DeserializeObject<ImageInfo>(json); iSettings = new ImageSettings { Width = 550, Level = "4d", NumBlocks = 4, TimeString = iInfo.Date.AddHours(Settings.Default.Difference).ToString("yyyy/MM/dd/HHmmss", CultureInfo.InvariantCulture) }; } } catch (WebException ex) { _notify(NotifificationType.Error, "Error receiving image information: " + ex.Message); } catch (Exception ex) { _notify(NotifificationType.Error, "Unknown error receiving image information: " + ex.Message); throw; } return iSettings; }
private ImageSettings GetLatestImageInfo() { ImageSettings iSettings = null; try { using (var wc = new WebClient()) { var json = wc.DownloadString("https://himawari8-dl.nict.go.jp/himawari8/img/D531106/latest.json?" + Guid.NewGuid()); var iInfo = JsonConvert.DeserializeObject <ImageInfo>(json); iSettings = new ImageSettings { Width = 550, Level = "4d", NumBlocks = 4, TimeString = iInfo.Date.AddHours(Settings.Default.Difference).ToString("yyyy/MM/dd/HHmmss", CultureInfo.InvariantCulture) }; } } catch (WebException ex) { _notify(NotifificationType.Error, "Error receiving image information: " + ex.Message); } catch (Exception ex) { _notify(NotifificationType.Error, "Unknown error receiving image information: " + ex.Message); throw; } return(iSettings); }
private Bitmap AssembleImageFrom(ImageSettings imageInfo) { Bitmap finalImage = null; var url = string.Format("http://himawari8-dl.nict.go.jp/himawari8/img/D531106/{0}/{1}/{2}", imageInfo.Level, imageInfo.Width, imageInfo.TimeString); finalImage = new Bitmap(imageInfo.Width * imageInfo.NumBlocks, imageInfo.Width * imageInfo.NumBlocks); var canvas = Graphics.FromImage(finalImage); canvas.Clear(Color.Black); try { for (var y = 0; y < imageInfo.NumBlocks; y++) { for (var x = 0; x < imageInfo.NumBlocks; x++) { var cUrl = url + "_" + x + "_" + y + ".png"; var request = WebRequest.Create(cUrl); var response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { using (var imagePart = Image.FromStream(response.GetResponseStream())) { canvas.DrawImage(imagePart, x * imageInfo.Width, y * imageInfo.Width, imageInfo.Width, imageInfo.Width); } } response.Close(); } } } catch (WebException ex) { Notify(NotifificationType.Error, "Error downloading latest image: " + ex.Message); } catch (Exception ex) { Notify(NotifificationType.Error, "Unknown error downloading latest image: " + ex.Message); throw; } return finalImage; }
private Bitmap AssembleImageFrom(ImageSettings imageInfo) { var url = $"https://himawari8-dl.nict.go.jp/himawari8/img/D531106/{imageInfo.Level}/{imageInfo.Width}/{imageInfo.TimeString}"; var finalImage = new Bitmap(imageInfo.Width * imageInfo.NumBlocks, imageInfo.Width * imageInfo.NumBlocks + 100); var canvas = Graphics.FromImage(finalImage); canvas.Clear(Color.Black); try { for (var y = 0; y < imageInfo.NumBlocks; y++) { for (var x = 0; x < imageInfo.NumBlocks; x++) { var cUrl = $"{url}_{x}_{y}.png"; var request = WebRequest.Create(cUrl); var response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { using (var imagePart = Image.FromStream(response.GetResponseStream())) { canvas.DrawImage(imagePart, x * imageInfo.Width, y * imageInfo.Width, imageInfo.Width, imageInfo.Width); } } response.Close(); } } } catch (WebException ex) { _notify(NotifificationType.Error, "Error downloading image: " + ex.Message); } catch (Exception ex) { _notify(NotifificationType.Error, "Unknown error downloading image: " + ex.Message); throw; } return(finalImage); }