- 积分
- 427
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2014-1-14
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 fancierhsj 于 2014-3-26 09:27 编辑
最近在开发一套B/S的云图和雷达图展示系统,主要展示AWX和GPF云图数据,SWAN和雷达基数据,发现MeteoInfo集成了大量的数据解析方法和图像生成功能,于是尝试用了一下,简单的DEMO,跟大家分享一下。使用的方法比较笨,也请大牛们指导一下有没有其他方法可以生成类似的透明图片。
-
- public void CreateGPFImage(){
- //GPF文件
- string aFile = Path.Combine(Application.StartupPath, "FY2E_2014_01_07_21_01_E_PJ2.gpf");
- //解析GPF文件,具体代码略
- GPFData g = ReadFormFile(aFile);
- //将解析的数据转换为GridData对象
- GridData gridData = new GridData();
- int XNum = g.wWidth;
- int YNum = g.wHeight;
- double[] array = new double[XNum];
- double[] array2 = new double[YNum];
- for (int i = 0; i < XNum; i++)
- {
- float xreso = g.fCLonRes;
- float startlon = 100;
- float lon = xreso * i + startlon;
- array = lon;
-
}
- for (int i = 0; i < YNum; i++)
- {
- float yreso = g.fCLatRes;
- float startlat = 5;
- float lat = startlat + i * yreso;
- array2 = lat;
- }
- gridData.X = array;
- gridData.Y = array2;
- gridData.MissingValue = -9999;
- double[,] array3 = new double[YNum, XNum];
- //加载调色板
- string palFile = Path.Combine(Application.StartupPath, "I-01.pal");
- LegendScheme aLS = new LegendScheme(ShapeTypes.Image);
- ImportFromPaletteFile_Unique(palFile, aLS);
- //第一通道数据
- gridData.Data = (double[,])g.dataRegion[0];
- string imgPath = Path.Combine(Application.StartupPath ,"gpf_channel_0.png");
- Image img = getImageFromGridData(gridData, aLS);
- img.Save(imgPath);
- }
- /// <summary>
- /// 从Grid创建图像
- /// </summary>
- /// <param name="gdata">GridData</param>
- /// <param name="als">色标</param>
- /// <returns></returns>
- public static Image getImageFromGridData(GridData gdata, LegendScheme als)
- {
- int width, height, breakNum;
- width = gdata.XNum;
- height = gdata.YNum;
- breakNum = als.BreakNum;
- double[] breakValue = new double[breakNum];
- Color[] breakColor = new Color[breakNum];
- for (int i = 0; i < breakNum; i++)
- {
- breakValue = Convert.ToDouble(als.LegendBreaks.EndValue);
- breakColor = als.LegendBreaks.Color;
- }
- Color defaultColor = breakColor[breakNum - 1]; //默认颜色为最后一个颜色
- Bitmap aBitmap = new Bitmap(width, height);
- for (int i = 0; i < height; i++)
- {
- for (int j = 0; j < width; j++)
- {
- double oneValue = gdata.Data[i, j];
- Color oneColor = defaultColor;
- //循环只到breakNum-1 是因为最后一个LegendBreaks的EndValue和StartValue是一样的
- for (int k = 0; k < breakNum - 1; k++)
- {
- if (oneValue < breakValue[k])
- {
- oneColor = breakColor[k];
- break;
- }
- }
- //如果整个调色板加载,整张图片都有颜色,因此过滤掉大于250的数值,另外可以在这里加入图片透明度的处理
- if (oneValue < 250)
- aBitmap.SetPixel(j, height - i - 1, Color.FromArgb(200, oneColor.R, oneColor.G, oneColor.B));
- }
- }
- Image aImage = (Image)aBitmap;
- return aImage;
- }
|
-
-
评分
-
查看全部评分
|