雲圖動畫,就是將一組序列圖以動畫的形式進行輪播,PIE SDK能夠將雲圖動畫以gif或avi格式進行導出,本文示例以雲圖動畫導出gif爲例,這樣只須要點開gif文件就能夠瀏覽雲圖動畫。html
下面來介紹下實現的主要代碼:工具
要實現雲圖動畫導出GIF步驟:動畫
一、加載序列時數據(能夠查看打開長時間序列數據)this
二、如何將雲圖動畫導出GIF文件;spa
雲圖動畫由一幀幀的畫面組合,也便是加載的序列圖的圖層數,將雲圖動畫導出GIF,主要是先將每一幀畫面保存爲圖片的格式,本文選擇png格式,而後將保存完的圖片經過第三方插件Gif.Components.dll生成GIF文件插件
1 /// <summary> 2 /// 雲圖動畫導出GIF 3 /// </summary> 4 /// <param name="sender"></param> 5 /// <param name="e"></param> 6 private void tbn_Export2GIF_Click(object sender, EventArgs e) 7 { 8 if (m_AnimationLayer.GetAnimationState() != 1 && m_AnimationLayer == null) return; 9 //一、設置保存GIF的路徑 10 if (!this.Enabled) return; 11 SaveFileDialog saveFileDialog = new SaveFileDialog(); 12 saveFileDialog.Title = "請選擇保存路徑"; 13 saveFileDialog.Filter = "GIF Files|*.gif;"; 14 if (saveFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; 15 string filePath = saveFileDialog.FileName; 16 17 DevExpress.Utils.WaitDialogForm waitDialogForm = new DevExpress.Utils.WaitDialogForm("正在生成GIF動畫,請耐心等候……", "生成GIF"); 18 19 //二、將每一幀圖都以png的格式保存在臨時文件夾下 20 string filePath_D = Path.Combine(@"..\Data\Temp\Pic", DateTime.Now.ToString("yyyyMMddhhmmss")); 21 Directory.CreateDirectory(filePath_D); 22 Export2PicSilent(filePath_D); 23 24 //三、將臨時文件夾下的每一幀圖片保存成GIF格式 25 string[] filePaths = Directory.GetFiles(filePath_D); 26 Parames_GeneralGIF para = new Parames_GeneralGIF(); 27 para.WaitDialogFormA = waitDialogForm; 28 para.PicPaths = filePaths; 29 para.GIFPath = filePath; 30 GeneralGif(para); 31 } 32 33 /// <summary> 34 /// 將每一幀動畫保存爲png圖 35 /// </summary> 36 /// <param name="folder">存放圖片的文件夾</param> 37 public void Export2PicSilent(string folder) 38 { 39 if (mapControlMain == null) return; 40 m_AnimationLayer.Stop(); 41 Image image = null; 42 for (int i = 0; i <= m_AnimationLayer.LayerCount - 1; i++) 43 { 44 m_AnimationLayer.SetCurrentFrameIndex(i); 45 mapControlMain.ActiveView.PartialRefresh(ViewDrawPhaseType.ViewAll); 46 System.Threading.Thread.Sleep(100); 47 image = mapControlMain.GetScreenshot(); 48 image.Save(folder + "\\" + i + ".png"); 49 } 50 m_AnimationLayer.Start(); 51 } 52 53 /// <summary> 54 /// 將幀圖片生成GIF 55 /// </summary> 56 /// <param name="param"></param> 57 public void GeneralGif(object param) 58 { 59 if (param == null) return; 60 Parames_GeneralGIF param_GeneralGIF = param as Parames_GeneralGIF; 61 if (param_GeneralGIF == null) return; 62 63 //生成gif圖片實例化 64 Gif.Components.AnimatedGifEncoder gifEncoder = new Gif.Components.AnimatedGifEncoder(); 65 gifEncoder.Start(param_GeneralGIF.GIFPath); 66 gifEncoder.SetDelay(300);//每幀播放時間 67 gifEncoder.SetRepeat(0); //-1:不重複,0:重複 68 69 for (int i = 0; i < param_GeneralGIF.PicPaths.Length; i++) 70 { 71 gifEncoder.AddFrame(System.Drawing.Image.FromFile(param_GeneralGIF.PicPaths[i])); 72 } 73 gifEncoder.Finish(); 74 param_GeneralGIF.WaitDialogFormA.Invoke(new Action(() => 75 { 76 param_GeneralGIF.WaitDialogFormA.Close(); 77 })); 78 }
代碼路徑:code
項目名稱orm |
百度雲盤地址下/PIE示例程序/13.小工具集錦/雲圖動畫導出/AnimationLayerExportToGIF視頻 |
數據路徑htm |
百度雲盤地址下/PIE示例數據/柵格數據/05.長時間序列數據 |
視頻路徑 |
百度雲盤地址下/PIE視頻教程/13.小工具集錦/雲圖動畫導出.avi |
注意:
在地圖初始化的時候,圖層樹控件須要手動綁定地圖控件:
tocControlMain.SetBuddyControl(mapControlMain as PIE.Carto.IPmdContents);
效果圖: