//合并单个Tiff文件 private void CombineSingleTiff(BackgroundWorker worker, TilesBounds tilesBounds, string tilePath, string outPutFilePath) { string outPutFileName = Path.Combine(outPutFilePath, string.Format("x{2}-{3}_y{0}-{1}.tif", tilesBounds.minRow, tilesBounds.maxRow, tilesBounds.minCol, tilesBounds.maxCol)); worker.ReportProgress(tilesBounds.minCol, string.Format("开始生成TIFF文件:{0}", outPutFileName)); if (File.Exists(outPutFileName)) { //存在则跳过 return; } int imageWidth = 256 * (tilesBounds.maxCol - tilesBounds.minCol + 1); int imageHeight = 256 * (tilesBounds.maxRow - tilesBounds.minRow + 1); TiffFileWriter writer = new TiffFileWriter(); writer.CreateFile(outPutFileName, (uint)imageWidth, (uint)imageHeight); writer.WriteTiffHeader(); for (int row = tilesBounds.minRow; row <= tilesBounds.maxRow; row++) { List <Bitmap> bitmapLs = new List <Bitmap>(tilesBounds.maxCol - tilesBounds.minCol + 1); try { for (int col = tilesBounds.minCol; col <= tilesBounds.maxCol; col++) { string sourceFileName = Path.Combine(tilePath, tilesBounds.zoomLevel.ToString(), col.ToString(), row.ToString() + fileExt); if (File.Exists(sourceFileName)) { bitmapLs.Add(new Bitmap(sourceFileName)); } else { bitmapLs.Add(new Bitmap(256, 256)); } } writer.WriteImageData(bitmapLs); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } writer.CloseFile(); string outTfwFileName = Path.Combine(outPutFilePath, Path.GetFileNameWithoutExtension(outPutFileName) + ".tfw"); WriteTfwFile(tilesBounds, outTfwFileName); }
//合并单个Tiff文件 private void CombineSingleTiff(BackgroundWorker worker, TilesBounds tilesBounds, string tilePath, string outPutFilePath) { string outPutFileName = Path.Combine(outPutFilePath, string.Format("x{2}-{3}_y{0}-{1}.tif", tilesBounds.minRow, tilesBounds.maxRow, tilesBounds.minCol, tilesBounds.maxCol)); worker.ReportProgress(tilesBounds.minCol, string.Format("开始生成TIFF文件:{0}", outPutFileName)); if (File.Exists(outPutFileName)) { //存在则跳过 return; } int imageWidth = 256 * (tilesBounds.maxCol - tilesBounds.minCol + 1); int imageHeight = 256 * (tilesBounds.maxRow - tilesBounds.minRow + 1); TiffFileWriter writer = new TiffFileWriter(); writer.CreateFile(outPutFileName, (uint)imageWidth, (uint)imageHeight); writer.WriteTiffHeader(); for (int row = tilesBounds.minRow; row <= tilesBounds.maxRow; row++) { List<Bitmap> bitmapLs = new List<Bitmap>(tilesBounds.maxCol - tilesBounds.minCol + 1); try { for (int col = tilesBounds.minCol; col <= tilesBounds.maxCol; col++) { string sourceFileName = Path.Combine(tilePath, tilesBounds.zoomLevel.ToString(), col.ToString(), row.ToString() + fileExt); if (File.Exists(sourceFileName)) { bitmapLs.Add(new Bitmap(sourceFileName)); } else { bitmapLs.Add(new Bitmap(256, 256)); } } writer.WriteImageData(bitmapLs); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } writer.CloseFile(); string outTfwFileName = Path.Combine(outPutFilePath, Path.GetFileNameWithoutExtension(outPutFileName) + ".tfw"); WriteTfwFile(tilesBounds, outTfwFileName); }