/// <summary> /// Downloads image from web /// </summary> protected void DownloadImage() { try { if (_imagePath != null) { Directory.CreateDirectory(Path.GetDirectoryName(this._imagePath)); } using (WebDownload downloadReq = new WebDownload(this._imageUrl)) { downloadReq.ProgressCallback += new DownloadProgressHandler(UpdateDownloadProgress); string filePath = getFilePathFromUrl(_imageUrl); if (_imagePath == null) { // Download to RAM downloadReq.DownloadMemory(); texture = ImageHelper.LoadTexture(downloadReq.ContentStream); } else { downloadReq.DownloadFile(_imagePath); UpdateTexture(_imagePath); } CreateMesh(); isInitialized = true; } } catch (ThreadAbortException) {} catch (Exception caught) { if (!showedError) { string msg = string.Format("Image download of file\n\n{1}\n\nfor layer '{0}' failed:\n\n{2}", name, _imageUrl, caught.Message); System.Windows.Forms.MessageBox.Show(msg, "Image download failed.", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); showedError = true; } if (_imagePath != null) { FileInfo imageFile = new FileInfo(_imagePath); if (imageFile.Exists) { UpdateTexture(_imagePath); CreateMesh(); isInitialized = true; } } else { isOn = false; } } }
public void DownloadImage() { try { this.downloadState = DownloadState.Downloading; this.downloadProgress = 0.0f; if (File.Exists(this.saveTexturePath)) { File.Delete(this.saveTexturePath); } if (!Directory.Exists(Path.GetDirectoryName(this.saveTexturePath))) { Directory.CreateDirectory(Path.GetDirectoryName(this.saveTexturePath)); } // Offline Check if (World.Settings.WorkOffline) { throw new Exception(); } using (WebDownload dl = new WebDownload(imageUrl)) { dl.ProgressCallback += new DownloadProgressHandler(UpdateProgress); dl.DownloadMemory(); this.downloadState = DownloadState.Converting; ImageHelper.ConvertToDxt1(dl.ContentStream, saveTexturePath); } if (this.downloadState == DownloadState.Cancelled) { return; } this.IsTextureAvailable = true; if (this.LoadImage) { this.imageLayer = new ImageLayer(this.Name, m_ParentWorld, this.layerRadius - (float)m_ParentWorld.EquatorialRadius, this.saveTexturePath, this.south, this.north, this.west, this.east, 255, /*this.terrainInfo*/ null); } this.downloadState = DownloadState.Pending; } catch (Exception caught) { Log.Write(caught); } }
/// <summary> /// Loads a bitmap from the web or a file and displays. /// </summary> public void LoadImage(string url) { if (url != null && !url.ToLower().StartsWith("http://")) { // Local file Image = Image.FromFile(url); return; } oldText = Text; Text = Text + ": Loading..."; using (WebDownload client = new WebDownload(url)) { client.DownloadMemory(); DownloadComplete(client); } }
internal void downloadThumbnail() { if (!MainForm.Settings.UseDappleSearch) { return; } WebDownload oThumbnailDownload = new WebDownload(MainForm.Settings.DappleSearchURL + "Thumbnail.aspx?layerid=" + m_aCommonAttributes["obaselayerid"], false); try { oThumbnailDownload.DownloadMemory(); m_oBitmap = new Bitmap(oThumbnailDownload.ContentStream); } catch (Exception) { m_oBitmap = Dapple.Properties.Resources.delete; } }