【问题标题】:How to create world file in C# from a tiff image?如何从 tiff 图像在 C# 中创建世界文件?
【发布时间】:2017-01-12 14:06:01
【问题描述】:

有什么简单的方法可以从 tiff 图像中提取 C# 中的world file

我有一个 tiff 图像,我需要创建一个没有任何第三方库的世界文件。

【问题讨论】:

    标签: c# tiff libtiff.net


    【解决方案1】:

    我找到了路……

        /// <summary>
        /// Create tfw - world file.
        /// </summary>
        /// <param name="filename">tif image full filename</param>
        private void CreateWorldFile(string filename)
        {
            using (var bitmapImage = new Bitmap(filename))
            {
                PropertyItem[] imageProps = bitmapImage.PropertyItems;
    
                var modelscale = imageProps.First(a => a.Id == GEOTIFF_MODELPIXELSCALETAG);
                var tiepoint = imageProps.First(a => a.Id == GEOTIFF_MODELTIEPOINTTAG);
    
                double x = BitConverter.ToDouble(tiepoint.Value, 0 + 24);
                double y = BitConverter.ToDouble(tiepoint.Value, 0 + 32);
    
                double xscale = BitConverter.ToDouble(modelscale.Value, 0);
                double yscale = BitConverter.ToDouble(modelscale.Value, 0 + 8);
    
                string tfwFileName = Path.GetDirectoryName(filename) + "\\" + Path.GetFileNameWithoutExtension(filename) + ".tfw";
    
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(tfwFileName))
                {
                    file.WriteLine(xscale);
                    file.WriteLine("0.0");
                    file.WriteLine("0.0");
                    file.WriteLine(yscale);
                    file.WriteLine(x);
                    file.WriteLine(y);
                }
            }
        }
    
        private readonly int GEOTIFF_MODELPIXELSCALETAG = 33550;
        private readonly int GEOTIFF_MODELTIEPOINTTAG = 33922;
    

    【讨论】:

    • 方法名有点奇怪难写,不应该是CreateWordFile吗?
    • @Master:不!请参阅提供的链接!
    • 如何做相反的事情,从 tif 和 tfw 文件创建 geotiff 地理参考 tiff 文件?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多