From 7fb323da219c84d0275e2e1138747899d8cdc40a Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期一, 22 七月 2024 14:19:41 +0800 Subject: [PATCH] 1 --- SimuTools/Tools/Handle.cs | 74 ++++++++++++++++++++++--------------- 1 files changed, 44 insertions(+), 30 deletions(-) diff --git a/SimuTools/Tools/Handle.cs b/SimuTools/Tools/Handle.cs index 4e9c384..b0dff5d 100644 --- a/SimuTools/Tools/Handle.cs +++ b/SimuTools/Tools/Handle.cs @@ -9,7 +9,6 @@ using System.Drawing; using System.IO; using System.Linq; -using System.Text; using System.Threading.Tasks; namespace SimuTools.Tools @@ -350,8 +349,8 @@ List<string> vyFiles = GetFiles(flowPath, "vy"); if (null == vxFiles || null == vyFiles || vxFiles.Count != vyFiles.Count || vxFiles.Count != layer.waters.data.Count) return; - //Parallel.For(0, vxFiles.Count, i => - for (int i = 0; i < vxFiles.Count; i++) + Parallel.For(0, vxFiles.Count, i => + //for (int i = 0; i < vxFiles.Count; i++) { Dataset vxDs = null, vyDs = null; try @@ -368,7 +367,7 @@ if (null != vxDs) vxDs.Dispose(); if (null != vyDs) vyDs.Dispose(); } - } + }); } /// <summary> @@ -414,33 +413,14 @@ vxDs.GetRasterBand(1).ReadRaster(0, 0, width, height, vxBuffer, width, height, 0, 0); vyDs.GetRasterBand(1).ReadRaster(0, 0, width, height, vyBuffer, width, height, 0, 0); - Bitmap image = new Bitmap(width, height); - Graphics graphic = Graphics.FromImage(image); - graphic.Clear(Color.Transparent); // 濉厖閫忔槑鑹� + //double[] vxMm = new double[2]; + //vxDs.GetRasterBand(1).ComputeRasterMinMax(vxMm, 0); + //double[] vyMm = new double[2]; + //vyDs.GetRasterBand(1).ComputeRasterMinMax(vyMm, 0); + //double min = vxMm[0] < vyMm[0] ? vxMm[0] : vyMm[0]; + //double max = vxMm[1] > vyMm[1] ? vxMm[1] : vyMm[1]; - // 鐢� R閫氶亾琛ㄧず锛屾祦鍚戜负褰掍竴鍖栫殑浜岀淮鍚戦噺锛坸,y锛夛紝G閫氶亾琛ㄧず涓� x *255 , B閫氶亾琛ㄧず涓� y * 255 - for (int x = 0; x < width; x++) - { - for (int y = 0; y < height; y++) - { - int offset = x + y * width; - float fx = GetFloatValue(vxBuffer[offset]); - float fy = GetFloatValue(vyBuffer[offset]); - - double dv = GetXyValue(fx, fy); - double dx = float.IsNaN(fx) ? 0 : fx * 0.5 + 0.5; - double dy = float.IsNaN(fy) ? 0 : fy * 0.5 + 0.5; - - int r = Convert.ToInt32(dv * 255); - int g = Convert.ToInt32(dx * 255); - int b = Convert.ToInt32(dy * 255); - - Color color = Color.FromArgb(127, r, g, b); - image.SetPixel(x, y, color); - } - } - - image.Save(png, System.Drawing.Imaging.ImageFormat.Png); + CreateFlowPng(vxBuffer, vyBuffer, png, width, height); } finally { @@ -452,6 +432,40 @@ } /// <summary> + /// 鍒涘缓娴侀�熸祦鍚慞NG + /// </summary> + private static void CreateFlowPng(float[] vxBuffer, float[] vyBuffer, string png, int width, int height) + { + Bitmap image = new Bitmap(width, height); + Graphics graphic = Graphics.FromImage(image); + graphic.Clear(Color.Transparent); // 濉厖閫忔槑鑹� + + // 鐢� R閫氶亾琛ㄧず锛屾祦鍚戜负褰掍竴鍖栫殑浜岀淮鍚戦噺锛坸,y锛夛紝G閫氶亾琛ㄧず涓� x *255 , B閫氶亾琛ㄧず涓� y * 255 + for (int x = 0; x < width; x++) + { + for (int y = 0; y < height; y++) + { + int offset = x + y * width; + float fx = GetFloatValue(vxBuffer[offset]); + float fy = GetFloatValue(vyBuffer[offset]); + + double dv = GetXyValue(fx, fy); + double dx = float.IsNaN(fx) ? 0 : fx * 0.5 + 0.5; + double dy = float.IsNaN(fy) ? 0 : fy * 0.5 + 0.5; + + int r = Convert.ToInt32(dv * 255); + if (r > 255) r = 255; + int g = Convert.ToInt32(dx * 255); + int b = Convert.ToInt32(dy * 255); + + Color color = Color.FromArgb(127, r, g, b); + image.SetPixel(x, y, color); + } + } + image.Save(png, System.Drawing.Imaging.ImageFormat.Png); + } + + /// <summary> /// 鑾峰彇Float鍊� /// </summary> private static float GetFloatValue(float val) -- Gitblit v1.9.3