//从内存加载图片 public void addGDIlayer(string layername, IImageDataProvider datapro, config cfg) { //delete existing same layer ILayer layer = this.mapBox.Map.GetLayerByName(layername); if (layer != null) { if (mp != null) { mp.Dispose(); mp = null; } if (img != null) { img.Dispose(); img = null; } if (p != null) { DeleteObject(p); } this.mapBox.Map.Layers.Remove(layer); ((Layer)layer).Dispose(); GC.Collect(); } //get data from data provider if (datapro == null) { DefaultData dd = new DefaultData(); mp = dd.GetData(); } else { mp = datapro.GetData(); } p = mp.GetHbitmap(); img = Image.FromHbitmap(p); ImageGDILayer gdilayer = new ImageGDILayer(layername, img, cfg); this.mapBox.Map.Layers.Insert(0, gdilayer); this.mapBox.Map.ZoomToBox(gdilayer.Envelope); this.mapBox.Refresh(); //System.Diagnostics.Process.GetCurrentProcess().MinWorkingSet = new System.IntPtr(5); }
/// <summary> /// Upload a set of images defined by the settings. /// </summary> /// <param name="requestHandler">Request handler</param> /// <param name="settings">Upload settings</param> public void DoImageUpload(IRequestHandler requestHandler, UploadSettings settings) { var imageData = settings.FilePaths.SelectMany(i => _imageDataProvider.GetData(i)).ToArray(); var totalCount = imageData.Length; var processedCount = 0; var successCount = 0; foreach (var imageItem in imageData) { processedCount++; var mimeType = ImageHelper.GetMimeType(Path.GetExtension(imageItem.FilePath)); if (mimeType == null) { Log.Warn($"Unsupported file type: {imageItem.FilePath}"); continue; } var fileInfo = new FileInfo(imageItem.FilePath); if (!fileInfo.Exists) { Log.Warn($"File does not exist: {imageItem.FilePath}"); continue; } InternalName internalName; if (!InternalName.TryParse(imageItem.InternalName, out internalName)) { Log.Warn($"Failed to parse internal name: {imageItem.InternalName}"); continue; } string md5Hash; using (var md5 = MD5.Create()) using (var stream = File.OpenRead(imageItem.FilePath)) { md5Hash = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLower(); } int width, height; using (var bitmap = new Bitmap(imageItem.FilePath)) { width = bitmap.Width; height = bitmap.Height; } var fileContent = Convert.ToBase64String(File.ReadAllBytes(imageItem.FilePath)); var file = new ImageResource { FolderName = imageItem.FolderName, FileRes = new FileResource { Name = internalName, Label = imageItem.Label, Alt = imageItem.Alt, Width = width, Height = height, }, FileName = fileInfo.Name, MimeType = mimeType, Md5 = md5Hash, FileContent = fileContent, }; var response = _imageWriteService.WriteImage(requestHandler, file); if (!response.Success) { Log.Warn($"Upload of {imageItem.InternalName} failed: {response.Message}"); } else { successCount++; } } Log.Info($"{successCount} images uploaded."); }