如何从tiff图像在C#中创建世界文件?

如何从tiff图像在C#中创建世界文件?,c#,tiff,libtiff.net,C#,Tiff,Libtiff.net,有没有简单的方法可以从tiff图像中提取C#中的图像 我有一个tiff图像,我需要创建一个没有任何第三方库的世界文件。我找到了 /// <summary> /// Create tfw - world file. /// </summary> /// <param name="filename">tif image full filename</param> private void CreateWorldF

有没有简单的方法可以从tiff图像中提取C#中的图像

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

我找到了

    /// <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;
//
///创建tfw-world文件。
/// 
///tif图像完整文件名
私有void CreateWorldFile(字符串文件名)
{
使用(var bitmapImage=新位图(文件名))
{
PropertyItem[]imageProps=bitmapImage.PropertyItems;
var modelscale=imageProps.First(a=>a.Id==GEOTIFF\u modelspixelscaletag);
var tiepoint=imageProps.First(a=>a.Id==GEOTIFF_MODELTIEPOINTTAG);
双x=位转换器。ToDouble(tiepoint.Value,0+24);
双y=位转换器。ToDouble(tiepoint.Value,0+32);
double xscale=BitConverter.ToDouble(modelscale.Value,0);
双yscale=位转换器.ToDouble(modelscale.Value,0+8);
字符串tfwFileName=Path.GetDirectoryName(文件名)+“\\”+Path.getFileName WithoutExtension(文件名)+“.tfw”;
使用(System.IO.StreamWriter file=new System.IO.StreamWriter(tfwFileName))
{
file.WriteLine(xscale);
file.WriteLine(“0.0”);
file.WriteLine(“0.0”);
文件写入线(yscale);
文件写入线(x);
文件写入线(y);
}
}
}
private readonly int GEOTIFF_MODELPIXELSCALETAG=33550;
私有只读int GEOTIFF_MODELTIEPOINTTAG=33922;
我找到了

    /// <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;
//
///创建tfw-world文件。
/// 
///tif图像完整文件名
私有void CreateWorldFile(字符串文件名)
{
使用(var bitmapImage=新位图(文件名))
{
PropertyItem[]imageProps=bitmapImage.PropertyItems;
var modelscale=imageProps.First(a=>a.Id==GEOTIFF\u modelspixelscaletag);
var tiepoint=imageProps.First(a=>a.Id==GEOTIFF_MODELTIEPOINTTAG);
双x=位转换器。ToDouble(tiepoint.Value,0+24);
双y=位转换器。ToDouble(tiepoint.Value,0+32);
double xscale=BitConverter.ToDouble(modelscale.Value,0);
双yscale=位转换器.ToDouble(modelscale.Value,0+8);
字符串tfwFileName=Path.GetDirectoryName(文件名)+“\\”+Path.getFileName WithoutExtension(文件名)+“.tfw”;
使用(System.IO.StreamWriter file=new System.IO.StreamWriter(tfwFileName))
{
file.WriteLine(xscale);
file.WriteLine(“0.0”);
file.WriteLine(“0.0”);
文件写入线(yscale);
文件写入线(x);
文件写入线(y);
}
}
}
private readonly int GEOTIFF_MODELPIXELSCALETAG=33550;
私有只读int GEOTIFF_MODELTIEPOINTTAG=33922;

方法名有点奇怪,不应该是
CreateWordFile
?@Master:不!请参阅提供的链接!方法名有点奇怪,不应该是
CreateWordFile
?@Master:不!请参阅提供的链接!