Thanks Frank.

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).

Thanks again,
Nik.


GDALDatasetH memDS = GDALCreate( GDALGetDriverByName("MEM"), "tmp", 256, 256, 
4, GDT_Float32, NULL );

…
…
…

char **options = NULL;

options = CSLSetNameValue( papszOptions, "WORLDFILE", "NO" );
options = CSLSetNameValue( papszOptions, "ZLEVEL", "9" );

GDALDatasetH dstDS = GDALCreate( hDriver, "/var/tmp/image.png", 256, 256, 4, 
GDT_Float32, options );
        GDALDatasetH dstDS = GDALCreateCopy( GDALGetDriverByName("PNG"), 
"/var/tmp/image.png", memDS, FALSE, options, NULL, NULL );


On 17/07/2013, at 4:50 PM, Frank Warmerdam <[email protected]> wrote:

> Nik,
> 
> 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:
> 
> gdalinfo --format png
> Format Details:
>   Short Name: PNG
>   Long Name: Portable Network Graphics
>   Extension: png
>   Mime Type: image/png
>   Help Topic: frmt_various.html#PNG
>   Supports: CreateCopy() - Create dataset by copying another.
>   Supports: Virtual IO - eg. /vsimem/
>   Creation Datatypes: Byte UInt16
> 
> <CreationOptionList>
>   <Option name="WORLDFILE" type="boolean" description="Create world file" />
>   <Option name="ZLEVEL" type="int" description="DEFLATE compression level 
> 1-9" default="6" />
> </CreationOptionList>
> 
> 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:
> 
> gdalinfo --formats
> ....
>   SDTS (rov): SDTS Raster
>   DTED (rwv): DTED Elevation Raster
>   PNG (rwv): Portable Network Graphics
>   JPEG (rwv): JPEG JFIF
>   MEM (rw+): In Memory Raster
> ...
> 
> The "w" means it supports at least CreateCopy(). The "+" means it supports 
> create+update.  
> 
> Best regards,
> 
> 
> 
> On Tue, Jul 16, 2013 at 10:14 PM, Nik Sands <[email protected]> wrote:
> Can I use GDALCreate to create (and later write to) PNG images?
> If so, is "PNG" the correct string for GDALGetDriverByName?
> 
> Otherwise, can somebody please let me know why the code below returns NULL 
> from GDALCreate (assigned to dstDS)?
> 
> Advice much appreciated, as always.
> 
> Thanks,
> Nik.
> 
> 
> 
>         GDALDriverH hDriver = GDALGetDriverByName("PNG");
>         char **papszOptions = NULL;
> 
>         papszOptions = CSLSetNameValue( papszOptions, "WORLDFILE", "NO" );
>         papszOptions = CSLSetNameValue( papszOptions, "ZLEVEL", "9" );
> 
>         GDALDatasetH dstDS = GDALCreate( hDriver, "/var/tmp/image.png", 256, 
> 256, 4, GDT_Float32, papszOptions );
> _______________________________________________
> gdal-dev mailing list
> [email protected]
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
> 
> 
> 
> -- 
> ---------------------------------------+--------------------------------------
> I set the clouds in motion - turn up   | Frank Warmerdam, [email protected]
> light and sound - activate the windows | http://pobox.com/~warmerdam
> and watch the world go round - Rush    | Geospatial Software Developer

_______________________________________________
gdal-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to