IWorkspaceFactory wf = new RasterWorkspaceFactory(); IWorkspace ws = wf.OpenFromFile(path, 0); IRasterWorkspace rastWork = (IRasterWorkspace)ws; IRasterDataset3 rds =(IRasterDataset3) rastWork.OpenRasterDataset(tmp+"2.img"); IRasterBandCollection rasterbands = (IRasterBandCollection)rds; IRaster raster = rds.CreateFullRaster(); RasterToText2(raster, path + "\\123.txt"); private void RasterToText2(IRaster raster, string txtFile) { var datas = RasterArray(raster); StreamWriter sw = new StreamWriter(txtFile, false, Encoding.UTF8); for (int i = 0; i < datas.GetLength(0); i++) { for (int j = 0; j < datas.GetLength(1); j++) { sw.Write(datas.GetValue(i, j).ToString() + " "); } sw.WriteLine(); } sw.Close(); } public static System.Array RasterArray(IRaster raster) { IRasterProps props = (IRasterProps)raster; //novalue = props.NoDataValue; IPnt pBlockSize = new PntClass(); pBlockSize.SetCoords((double)props.Width, (double)props.Height); IRaster2 raster2 = (IRaster2)raster; IPixelBlock pixelBlock = raster2.CreateCursorEx(pBlockSize).PixelBlock; pBlockSize.SetCoords(0.0, 0.0); raster.Read(pBlockSize, pixelBlock); IPixelBlock3 block2 = (IPixelBlock3)pixelBlock; return (System.Array)block2.get_PixelData(0); }