继上篇文章,本次打开TIFF文件,附上源码及其注释
private void button2_Click(object sender, EventArgs e) { axMapControl1.ClearLayers(); if (tiffPath == "") return; int Index = tiffPath.LastIndexOf("\"); string fileName = tiffPath.Substring(Index+1); string filePath = tiffPath.Substring(0, Index); IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactoryClass();//利用工厂对象去生成一个raster文件的工作空间 IRasterWorkspace pRasterWorkspace = (IRasterWorkspace)pWorkspaceFactory.OpenFromFile(filePath, 0);//到指定路径下 IRasterDataset pRasterDataset = (IRasterDataset)pRasterWorkspace.OpenRasterDataset(fileName);//利用要素集去接收对应的raster文件 IRasterLayer pRasterLayer = new RasterLayerClass();//生成一个矢量图层对象 pRasterLayer.CreateFromDataset(pRasterDataset);//利用矢量图层对象去创建对应的raster文件 axMapControl1.Map.AddLayer(pRasterLayer);//添加对应的图层 axMapControl1.ActiveView.Refresh(); }