爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 5309|回复: 6

micaps云图数据转换JPG图片

[复制链接]

新浪微博达人勋

发表于 2011-11-6 20:09:36 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
        小弟以前从来没有搞过气象这行。MeteoInfo的开源让我很感动。这二天用了一下,还蛮好用。下面贴出我写的一个将micaps数据(MST1红外图像)转换成图片的程序的。希望对大家有一点点用。


  1. /// <summary>
  2. /// 云图micaps数据转换成JPG文件
  3. /// </summary>
  4. /// <param name="path"></param>
  5. private void MicapsCloudJPG(FileInfo path)
  6. {
  7. MICAPS13DataInfo aDataInfo = new MICAPS13DataInfo();
  8. aDataInfo.ReadDataInfo(path.FullName);

  9. ImageLayer aImageLayer = DrawMeteoData.CreateImageLayer(aDataInfo.ImageBytes,
  10. aDataInfo.XNum, aDataInfo.YNum, aDataInfo.WorldFileP, "Image");

  11. string palFile = Application.StartupPath + @"\I-01.pal";
  12. aImageLayer.SetPalette(palFile);

  13. try
  14. {
  15. Image img = aImageLayer.Image;
  16. if (IsPixelFormatIndexed(img.PixelFormat))
  17. {
  18. Bitmap bmp = new Bitmap(img.Width, img.Height, PixelFormat.Format32bppArgb);
  19. using (Graphics g = Graphics.FromImage(bmp))
  20. {
  21. g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
  22. g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
  23. g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
  24. g.DrawImage(img, 0, 0);

  25. ///加入背景图片,将中国地图网格线加放在云图图片上。
  26. System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Application.StartupPath + @"\weather.png");
  27. g.DrawImage(copyImage, new Rectangle(0, 0, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);

  28. Font f = new Font("微软雅黑", 15);
  29. string datestr=path.Name.Split('.')[0];
  30. datestr = "20" + datestr.Substring(0, 2) + "年" + datestr.Substring(2, 2) + "月" + datestr.Substring(4, 2) + "日" + datestr.Substring(6, 2) + "分MST1红外图像";
  31. g.DrawString(datestr, f, Brushes.Red, new PointF(10, 470));
  32. string newfiles = Application.StartupPath + "\\out\" + path.Name.Split('.')[0] + ".jpg";
  33. bmp.Save(newfiles, System.Drawing.Imaging.ImageFormat.Jpeg);
  34. g.Dispose();
  35. bmp = null;
  36. }
  37. }
  38. }
  39. catch (Exception ex)
  40. { MessageBox.Show(ex.Message); }
  41. }


  42. private static PixelFormat[] indexedPixelFormats = {
  43. PixelFormat.Undefined,
  44. PixelFormat.DontCare,
  45. PixelFormat.Format16bppArgb1555,
  46. PixelFormat.Format1bppIndexed,
  47. PixelFormat.Format4bppIndexed,
  48. PixelFormat.Format8bppIndexed
  49. };


  50. private static bool IsPixelFormatIndexed(PixelFormat imgPixelFormat)
  51. {
  52. foreach (PixelFormat pf in indexedPixelFormats)
  53. {
  54. if (pf.Equals(imgPixelFormat)) return true;
  55. }
  56. return false;
  57. }
复制代码

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-11-6 21:23:35 | 显示全部楼层
厉害,把程序共享一下让我们学习一下嘛,呵呵
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-11-6 21:37:20 | 显示全部楼层
谢谢分享
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-11-6 22:42:58 | 显示全部楼层
不错,希望能有更多的共享
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2012-1-28 21:04:41 | 显示全部楼层
我要多学习下了。。。C#
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2013-10-23 16:29:41 | 显示全部楼层
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-12-28 12:01:06 | 显示全部楼层
谢谢分享 好东西
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表