public static void Test() { try { // Register Gdal.AllRegister(); // Only works for reading data but not for creating datasets. // string strFilePath = @"C:\Users\Administrator\minigis2\data\gdal_data\092b05.tif"; string strFilePath = @"C:\1.bmp"; //String strFormatCode = "GTiff"; //Driver driver=Gdal.GetDriverByName(strFormatCode); //driver.Register(); // Works for reading and creating datasets. // Open dataset Dataset ds = Gdal.Open(strFilePath, Access.GA_ReadOnly); if (ds != null) { // Get Raster Parameters int xSize = ds.RasterXSize; int ySize = ds.RasterYSize; int bands = ds.RasterCount; string strProjectionRef = ds.GetProjectionRef(); MessageBox.Show("image width=" + xSize + ",height=" + ySize + ", bands=" + bands); // Get Transform double[] adfGeoTransform = new double[6]; ds.GetGeoTransform(adfGeoTransform); double originX = adfGeoTransform[0]; double originY = adfGeoTransform[3]; double pixelWidth = adfGeoTransform[1]; double pixelHeight = adfGeoTransform[5]; // xOffset=int((x-originX)/pixelWidth) // yOffset=int((y-originY)/pixelHeight) } // Get Driver OSGeo.GDAL.Driver driver = ds.GetDriver(); if (driver != null) { string strDescription = driver.GetDescription(); string strLongName = driver.LongName; string strShortName = driver.ShortName; } // Get Raster Band for (int iBand = 1; iBand <= ds.RasterCount; iBand++) { // 1-based Band band = ds.GetRasterBand(iBand); string dataType = band.DataType.ToString(); int xSize = band.XSize; int ySize = band.YSize; string colorInterp = band.GetRasterColorInterpretation().ToString(); for (int iOver = 0; iOver < band.GetOverviewCount(); iOver++) { Band over = band.GetOverview(iOver); string overDataType = over.DataType.ToString(); int overXSize = over.XSize; int overYSize = over.YSize; string overColorInterp = over.GetRasterColorInterpretation().ToString(); } } // Processing the raster data //SaveBitmapBuffered(ds, @"C:\1new.jpg"); } catch (Exception err) { MessageBox.Show(err.Message); } }