title: Create a geotiff from an existing bitmap in C# with gdal
body: <p>I have to use gdal in a c# project. The thing I have to do is to "convert" a simple bitmap into a GeoTiff. I read some documentation on the gdal website but I didn't succeed to make it work perfectly. In fact my bitmap is successfuly exported to a geotiff, but if I open the geotiff with a GIS software (for instance QuantumGIS) the GeoTiff is inverted on the y-axis :</p>
  
  <p><img src="https://i.stack.imgur.com/WYlAn.png" alt="enter image description here"> :</p>
  
  <p>Whereas the original bitmap look like this :</p>
  
  <p><img src="https://i.stack.imgur.com/8gb3K.png" alt="enter image description here"></p>
  
  <p>Here is what I've done :</p>
  
  <p>First I write a temp file to the disk (that is the bitmap), I create a dataset containing the bitmap thanks to gdal function (Gdal.Open(path)), and I create a new dataset (with the GTiff driver) using the bitmap dataset , I set the geo transformation and I write the geotiff to the disk :</p>
  
  <pre><code>  String wktProj = null;
    String tmpPath = @"C:\tmp.bmp";
    Bitmap tmpBitmap = bmp.Clone(new Rectangle(0, 0, bmp.Width, bmp.Height), pixFormat);
    tmpBitmap.Save(tmpPath, ImageFormat.Bmp);
  
    String[] options = null;
    Gdal.AllRegister();
    OSGeo.GDAL.Driver srcDrv = Gdal.GetDriverByName("GTiff");
    Dataset srcDs = Gdal.Open(tmpPath, Access.GA_ReadOnly);
    Dataset dstDs = srcDrv.CreateCopy(path, srcDs, 0, options, null, null);
  
    //Set the map projection
    Osr.GetWellKnownGeogCSAsWKT("WGS84", out wktProj);
    dstDs.SetProjection(wktProj);
  
    //Set the map georeferencing
    double mapWidth = Math.Abs(latLongMap.listBounds.topRight.x - latLongMap.listBounds.bottomLeft.x);
    double mapHeight = Math.Abs(latLongMap.listBounds.topRight.y - latLongMap.listBounds.bottomLeft.y);
    double[] geoTransfo = new double[] { -5.14, mapWidth / bmp.Width, 0, 48.75, 0, mapHeight / bmp.Height };
    dstDs.SetGeoTransform(geoTransfo);
  
    dstDs.FlushCache();
    dstDs.Dispose();
    srcDs.Dispose();
    srcDrv.Dispose();
    tmpBitmap.Dispose();
  
    File.Delete(tmpPath);
  </code></pre>
  
  <p>Any idea on what I'm doing wrong ?</p>
  
  <p><strong>Edit</strong> I don't know if it is important but the pixels bitmap are 8bppIndexed.</p>