<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Thanks Frank.</div><div><br></div><div>So I think I need to do something like the code below instead, ie, create a "MEM" dataset and later create-copy to a "PNG" dataset. This seems to be working (although the content of the image is all wrong - but that's another issue for me to try to figure out).</div><div><br></div><div>Thanks again,</div><div>Nik.</div><div><br></div><div><br></div><div>GDALDatasetH memDS = GDALCreate( GDALGetDriverByName("MEM"), "tmp", 256, 256, 4, GDT_Float32, NULL );</div><div><br></div><div>…</div><div>…</div><div>…</div><div><br></div><div>char **options = NULL;</div><div><br></div><div>options = CSLSetNameValue( papszOptions, "WORLDFILE", "NO" );</div><div>options = CSLSetNameValue( papszOptions, "ZLEVEL", "9" );</div><div><br></div><div>GDALDatasetH dstDS = GDALCreate( hDriver, "/var/tmp/image.png", 256, 256, 4, GDT_Float32, options );</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>GDALDatasetH dstDS = GDALCreateCopy( GDALGetDriverByName("PNG"), "/var/tmp/image.png", memDS, FALSE, options, NULL, NULL );</div><div><br></div><div><br></div><div><div>On 17/07/2013, at 4:50 PM, Frank Warmerdam <<a href="mailto:warmerdam@pobox.com">warmerdam@pobox.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div><div><div><div>Nik,<br><br></div>No, the PNG format does not support direct creation, only creation by copying an existing dataset (GDALCreateCopy()). You can interactively see the capabilities of a driver like this:<br>
<br>gdalinfo --format png<br>Format Details:<br> Short Name: PNG<br> Long Name: Portable Network Graphics<br> Extension: png<br> Mime Type: image/png<br> Help Topic: frmt_various.html#PNG<br> Supports: CreateCopy() - Create dataset by copying another.<br>
Supports: Virtual IO - eg. /vsimem/<br> Creation Datatypes: Byte UInt16<br><br><CreationOptionList><br> <Option name="WORLDFILE" type="boolean" description="Create world file" /><br>
<Option name="ZLEVEL" type="int" description="DEFLATE compression level 1-9" default="6" /><br></CreationOptionList><br><br></div>The "Supports: CreateCopy()" means you can create the format, but only by copying an existing dataset. Formats supporting creation will have "Supports: Create()". You can get a broad listing of all formats like this:<br>
<br>gdalinfo --formats<br>....<br> SDTS (rov): SDTS Raster<br> DTED (rwv): DTED Elevation Raster<br> PNG (rwv): Portable Network Graphics<br> JPEG (rwv): JPEG JFIF<br> MEM (rw+): In Memory Raster<br>...<br><br></div>
The "w" means it supports at least CreateCopy(). The "+" means it supports create+update. <br><br></div>Best regards,<br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 16, 2013 at 10:14 PM, Nik Sands <span dir="ltr"><<a href="mailto:nixanz@nixanz.com" target="_blank">nixanz@nixanz.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Can I use GDALCreate to create (and later write to) PNG images?<br>
If so, is "PNG" the correct string for GDALGetDriverByName?<br>
<br>
Otherwise, can somebody please let me know why the code below returns NULL from GDALCreate (assigned to dstDS)?<br>
<br>
Advice much appreciated, as always.<br>
<br>
Thanks,<br>
Nik.<br>
<br>
<br>
<br>
GDALDriverH hDriver = GDALGetDriverByName("PNG");<br>
char **papszOptions = NULL;<br>
<br>
papszOptions = CSLSetNameValue( papszOptions, "WORLDFILE", "NO" );<br>
papszOptions = CSLSetNameValue( papszOptions, "ZLEVEL", "9" );<br>
<br>
GDALDatasetH dstDS = GDALCreate( hDriver, "/var/tmp/image.png", 256, 256, 4, GDT_Float32, papszOptions );<br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>---------------------------------------+--------------------------------------<br>I set the clouds in motion - turn up | Frank Warmerdam, <a href="mailto:warmerdam@pobox.com" target="_blank">warmerdam@pobox.com</a><br>
light and sound - activate the windows | <a href="http://pobox.com/~warmerdam" target="_blank">http://pobox.com/~warmerdam</a><br>and watch the world go round - Rush | Geospatial Software Developer<br>
</div>
</blockquote></div><br></body></html>