Hi all,
Is there any example (or a hint) of converting a System.Drawing.Bitmap into GDAL Dataset? Regards, Maksim Sestic |
For an example of the reverse action see SaveBitMapDirect in GDALReadDirect.cs
To write data to GDAL dataset see: GDALWrite.cs or GDALDatasetWrite.cs
Best regards, Tamas 2013/3/22 Maksim Sestic <[hidden email]> Hi all, _______________________________________________ gdal-dev mailing list [hidden email] http://lists.osgeo.org/mailman/listinfo/gdal-dev |
This is because there's no driver to recognise the image data directly. You should provide the image file in a GDAL supported binary format (like jpg or png or tif) or use the MEM driver to represent the dataset. I've created a new sample for this approach at:
In this example I create the bands in a reverse order as it looks like the Windows bitmap format requires it.
Best regards, Tamas 2013/3/23 Maksim Sestic <[hidden email]>
_______________________________________________ gdal-dev mailing list [hidden email] http://lists.osgeo.org/mailman/listinfo/gdal-dev |
We could also convert the bitmap to png or some other formats that the GDAL drivers reconise, something like: byte[] imageBuffer; using (MemoryStream stream = new MemoryStream())
{ bmp.Save(stream, ImageFormat.Png); imageBuffer = stream.ToArray(); } Gdal.FileFromMemBuffer(memFilename, imageBuffer);
Dataset ds = Gdal.Open(memFilename, Access.GA_ReadOnly); Best regards, Tamas 2013/3/24 Tamas Szekeres <[hidden email]> This is because there's no driver to recognise the image data directly. You should provide the image file in a GDAL supported binary format (like jpg or png or tif) or use the MEM driver to represent the dataset. I've created a new sample for this approach at: _______________________________________________ gdal-dev mailing list [hidden email] http://lists.osgeo.org/mailman/listinfo/gdal-dev |
Hi Tamas, Yes, finally, "vsimem" works
once bitmap is Png (abbreviated VB.NET code follows): Dim bmp As Bitmap = Bitmap.FromFile("C:\Input.tif")
Dim imageBuffer As Byte()
Using stream As New MemoryStream()
bmp.Save(stream, ImageFormat.Png)
imageBuffer = stream.ToArray()
End Using
Dim pinnedArray As GCHandle = GCHandle.Alloc(imageBuffer, GCHandleType.Pinned)
Dim pointer As IntPtr = pinnedArray.AddrOfPinnedObject()
Dim memFilename As String = "/vsimem/data"
Gdal.FileFromMemBuffer(memFilename,
imageBuffer.Length, pointer)
Dim ds As Dataset = Gdal.Open(memFilename, Access.GA_ReadOnly)
Dim drv As Driver = Gdal.GetDriverByName("GTiff")
Dim ds1 =
drv.CreateCopy("C:\Output.tif",
ds, 0, Nothing, Nothing, Nothing)
pinnedArray.Free() I've tested it on bitmaps originating
from .bmp, .png, .tif and .jpg. Regards, Maksim Sestic From:
Tamas Szekeres [mailto:[hidden email]] We could also convert the bitmap to png or some other formats that the
GDAL drivers reconise, something like: byte[] imageBuffer; using (MemoryStream stream = new
MemoryStream()) { bmp.Save(stream,
ImageFormat.Png); imageBuffer =
stream.ToArray(); } Gdal.FileFromMemBuffer(memFilename,
imageBuffer); Dataset ds = Gdal.Open(memFilename,
Access.GA_ReadOnly); Best regards, Tamas _______________________________________________ gdal-dev mailing list [hidden email] http://lists.osgeo.org/mailman/listinfo/gdal-dev |
Free forum by Nabble | Edit this page |