I am developing a plugin for MapInfo and I have BMP image with all the prop and I have rectbounds. I have done through GDAL using the below solution. But I am not getting proper output which I am expecting. I am getting some extra white patches in my TAB tab after converstion. I believe this is happening because of GDAL.
This is my code:
Bitmap bmp = CreateChartTIF(path);
GdalConfiguration.TryConfiguration();
String wktProj = null;
String tmpPath = @"E:\@@MapInfo_1\tmp.bmp";
int a = Convert.ToInt16(rectBounds.Left);
int b = Convert.ToInt16(rectBounds.Top);
bmp.Save(tmpPath, ImageFormat.Bmp);
System.IO.MemoryStream mem = new System.IO.MemoryStream();
mem.Flush();
String[] options = null;
Gdal.AllRegister();
OSGeo.GDAL.Driver srcDrv = Gdal.GetDriverByName("GTiff");
Dataset srcDs = Gdal.Open(tmpPath, Access.GA_ReadOnly);
Dataset dstDs = srcDrv.CreateCopy(@"E:\@@MapInfo_1\Output\2-0.tif", srcDs, 0, options, null, null);
Osr.GetWellKnownGeogCSAsWKT("WGS84", out wktProj);
dstDs.SetProjection(wktProj);
double minx = rectBounds.Left;
double miny = rectBounds.Bottom;
double maxx = rectBounds.Right;
double maxy = rectBounds.Top;
double mapWidth = Math.Abs(minx - maxx);
double mapHeight = Math.Abs(maxy - miny);
double pixel1 = mapWidth / bmp.Width;
double pixel2 = mapHeight / bmp.Height;
//Top Left x, w-r pixel resln, 0, Top Letf y, 0, n-s pixel resln
double[] geoTransfo = new double[] { minx, pixel1, 0, maxy, 0, pixel2 * (-1) }
dstDs.SetGeoTransform(geoTransfo);
dstDs.FlushCache();
dstDs.Dispose();
srcDs.Dispose();
srcDrv.Dispose();
bmp.Dispose();
RasterProcessing.Convert(@"E:\@@MapInfo_1\Output\2-0.tif", "E:\\@@MapInfo_1\\Jonathan_Test.mrr", "MI_MRR");
Please find the screenshot below :
Any idea or any sample code? Is there any way to remove GDAL dependency and do this conversion using MapXtreme?