<br><br><div class="gmail_quote">2010/5/26 Even Rouault <span dir="ltr"><<a href="mailto:even.rouault@mines-paris.org">even.rouault@mines-paris.org</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Felix,<br>
<br>
yes you should be able to use FileFromMemBuffer() to create a virtual file and<br>
open it with the PNG driver (since the PNG driver supports virtual IO --> as<br>
confirmed by gdalinfo --format PNG)<br>
<br>
Here's the C API for it :<br>
<a href="http://gdal.org/cpl__vsi_8h.html#1ecb3a78729ecea4d2ce22065a605244" target="_blank">http://gdal.org/cpl__vsi_8h.html#1ecb3a78729ecea4d2ce22065a605244</a><br>
<br>
And here's an extract of a test in the Python autotest suite.<br>
<br>
content = open('data/byte.tif', mode='rb').read()<br>
<br>
# Create in-memory file and initialize it with the content<br>
gdal.FileFromMemBuffer('/vsimem/tiffinmem', content)<br>
<br>
# Open the in-memory file<br>
ds = gdal.Open('/vsimem/tiffinmem')<br>
<br>
# do something with the dataset<br>
<br>
# Close the dataset<br>
ds = None<br>
<br>
# Release memory associated to the in-memory file<br>
gdal.Unlink('/vsimem/tiffinmem')<br>
<br>
<br>
Disclaimer: You should be able to adapt the above for C#, but I haven't tested<br>
with the C# bindings, so there's a risk that they aren't ready if there's<br>
some missing required typemap.<br>
<br></blockquote><div><br>Felix,<br><br><br>The current version of the C# signature of FileFromMemBuffer is rude and not user friendly, though I could imagine the following transcript of the python code above for the C# bindings (not tested):<br>
<br><br></div></div>byte[] bytes = File.ReadAllBytes("data\\byte.tif");<br>GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);<br>try<br>{<br> Gdal.FileFromMemBuffer("/vsimem/tiffinmem", handle.AddrOfPinnedObject());<br>
<br> using (Dataset ds = gdal.Open("/vsimem/tiffinmem"))<br> {<br> // do something<br> }<br> Gdal.Unlink("/vsimem/tiffinmem");<br>}<br>finally<br>{<br> handle.Free();<br>}<br><br><br>
In the future I'm about to add a second signature to the bindings "<b>public static void FileFromMemBuffer(string pszFilename, int nBytes, byte[] pabyData)</b>" which could also avoid the extra memcopy implemented in the current version.<br>
<br>Feel free to <a href="http://trac.osgeo.org/gdal/newticket">add a ticket</a> to require this addition.<br><br><br>Best regards,<br><br>Tamas<br><br>