[Gdal-dev] C# Bindings

Tamas Szekeres szekerest at gmail.com
Wed Nov 8 18:11:31 EST 2006


>
> Right. So, for now, let's leave out the unsafe methods then. At some
> point, I might do some speed comparisons between the IntPtr version and
> the typesafe version. If there's a significant speed penalty (which I
> doubt) then we can revisit the idea of adding optional unsafe/fast methods.
>

Simon,

I've added some of the typesafe overloads so you can make the comparison easily.
I've tested the code with the following sample:


        // Get the width and height of the Dataset
        int width = ds.RasterXSize;
        int height = ds.RasterYSize;

        // Create a Bitmap to store the GDAL image in
        Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppRgb);

        double[] r = new double[width * height];
        double[] g = new double[width * height];
        double[] b = new double[width * height];

        // Get the GDAL Band objects from the Dataset
        Band redBand = ds.GetRasterBand(1);
        Band greenBand = ds.GetRasterBand(2);
        Band blueBand = ds.GetRasterBand(3);

        redBand.ReadRaster(0, 0, width, height, r, width, height, 0, 0);
        greenBand.ReadRaster(0, 0, width, height, g, width, height, 0, 0);
        blueBand.ReadRaster(0, 0, width, height, b, width, height, 0, 0);

        int i, j;
        for (i = 0; i< width; i++)
        {
            for (j=0; j<height; j++)
            {
                Color newColor =
Color.FromArgb(Convert.ToInt32(r[i+j*width]),Convert.ToInt32(g[i+j*width]),
Convert.ToInt32(b[i+j*width]));
                bitmap.SetPixel(i, j, newColor);
            }
        }

        bitmap.Save("Data/myfile1.bmp");


At this point I'm a bit uncertain about the proper handling of the
following types:

GDT_UInt16
GDT_UInt32
GDT_CInt16
GDT_CInt32
GDT_CFloat32
GDT_CFloat64

And also I couldn't ignore a serious bug in the SWIG default
implementation caused access violations and I've made a temporary fix
exclusively for the GDAL C# binding.
However it must be noted that this issue exists for some of the other
bindings like Java as well. It have involved the need of
reimplementing how the SWIG wrapper classes handle the internal C
memory segments.

Did you mean that the buffer offset parameter should be added only to
the IntPtr overloads?


Best Regards,

Tamas



More information about the Gdal-dev mailing list