- 积分
- 55
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-11-6
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
小弟以前从来没有搞过气象这行。MeteoInfo的开源让我很感动。这二天用了一下,还蛮好用。下面贴出我写的一个将micaps数据(MST1红外图像)转换成图片的程序的。希望对大家有一点点用。
- /// <summary>
- /// 云图micaps数据转换成JPG文件
- /// </summary>
- /// <param name="path"></param>
- private void MicapsCloudJPG(FileInfo path)
- {
- MICAPS13DataInfo aDataInfo = new MICAPS13DataInfo();
- aDataInfo.ReadDataInfo(path.FullName);
- ImageLayer aImageLayer = DrawMeteoData.CreateImageLayer(aDataInfo.ImageBytes,
- aDataInfo.XNum, aDataInfo.YNum, aDataInfo.WorldFileP, "Image");
- string palFile = Application.StartupPath + @"\I-01.pal";
- aImageLayer.SetPalette(palFile);
- try
- {
- Image img = aImageLayer.Image;
- if (IsPixelFormatIndexed(img.PixelFormat))
- {
- Bitmap bmp = new Bitmap(img.Width, img.Height, PixelFormat.Format32bppArgb);
- using (Graphics g = Graphics.FromImage(bmp))
- {
- g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
- g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
- g.DrawImage(img, 0, 0);
- ///加入背景图片,将中国地图网格线加放在云图图片上。
- System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Application.StartupPath + @"\weather.png");
- g.DrawImage(copyImage, new Rectangle(0, 0, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);
- Font f = new Font("微软雅黑", 15);
- string datestr=path.Name.Split('.')[0];
- datestr = "20" + datestr.Substring(0, 2) + "年" + datestr.Substring(2, 2) + "月" + datestr.Substring(4, 2) + "日" + datestr.Substring(6, 2) + "分MST1红外图像";
- g.DrawString(datestr, f, Brushes.Red, new PointF(10, 470));
- string newfiles = Application.StartupPath + "\\out\" + path.Name.Split('.')[0] + ".jpg";
- bmp.Save(newfiles, System.Drawing.Imaging.ImageFormat.Jpeg);
- g.Dispose();
- bmp = null;
- }
- }
- }
- catch (Exception ex)
- { MessageBox.Show(ex.Message); }
- }
-
- private static PixelFormat[] indexedPixelFormats = {
- PixelFormat.Undefined,
- PixelFormat.DontCare,
- PixelFormat.Format16bppArgb1555,
- PixelFormat.Format1bppIndexed,
- PixelFormat.Format4bppIndexed,
- PixelFormat.Format8bppIndexed
- };
-
- private static bool IsPixelFormatIndexed(PixelFormat imgPixelFormat)
- {
- foreach (PixelFormat pf in indexedPixelFormats)
- {
- if (pf.Equals(imgPixelFormat)) return true;
- }
- return false;
- }
复制代码
|
|