Ejemplo n.º 1
0
 public void WriteTIFF(string path)
 {
     TIFFWriter.ExportTIFF(_bitmap, path);
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                WriteInstructions();
            }
            else
            {
                bool verbose = false;
                int  i = 0, count = args.Length;

                if (args[0] == "-verbose")
                {
                    verbose = true;
                    i++;

                    if (args.Length == 1)
                    {
                        WriteInstructions();
                        Environment.Exit(0);
                    }
                }

                for (; i < count; i++)
                {
                    try
                    {
                        FileStream   file   = File.Open(args[i], FileMode.Open);
                        BinaryReader reader = new BinaryReader(file);

                        SRTMFormat format = SRTMFormat.Unknown;

                        if (file.Length == 3601 * 3601 * sizeof(Int16))
                        {
                            format = SRTMFormat.SRTM1;
                        }
                        else if (file.Length == 1201 * 1201 * sizeof(Int16))
                        {
                            format = SRTMFormat.SRTM3;
                        }

                        if (verbose)
                        {
                            Console.WriteLine("Reading SRTM file: " + args[i]);
                            Console.WriteLine(" - Length: " + file.Length + " Bytes");
                            Console.WriteLine(" - Format: " + format.ToString() + Environment.NewLine);
                        }

                        SRTMReader srtm = new SRTMReader(reader, format);
                        srtm.ReadAllData(false);

                        BitmapTerrain bmpTerrain = new BitmapTerrain(srtm.GetTileSize(), srtm.GetTileSize());
                        bmpTerrain.ConvertFromSRTM(srtm, BitmapChannels.ChannelRed | BitmapChannels.ChannelGreen);

                        if (verbose)
                        {
                            Console.WriteLine("Writing TIFF file from SRTM file...");
                        }

                        string tiffPath = args[i];
                        int    dot      = tiffPath.IndexOf('.');
                        tiffPath  = tiffPath.Substring(0, dot);
                        tiffPath += ".tiff";

                        TIFFWriter.ExportTIFF(bmpTerrain.GetBitmap(), tiffPath);

                        if (verbose)
                        {
                            Console.WriteLine("Success" + Environment.NewLine);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (verbose)
                        {
                            Console.WriteLine("Couldn't convert SRTM file:");
                            Console.WriteLine(ex.Message + Environment.NewLine);
                        }
                    }
                }
            }
        }