[Gdal-dev] pb creating a bmp

Stephane Routelous route at cae.com
Mon Sep 27 15:11:45 EDT 2004


Hi,

i'm using GDAL 1.2.2.0, released 2004/08/16 on Windows 2000 with
VisualC++6.0 SP5

I was working with bmp file :
	
void testGDAL()
{
	GDALAllRegister();
    GDALDriver *poDriver;
    char **papszMetadata;

    poDriver = GetGDALDriverManager()->GetDriverByName("BMP");

    if( poDriver == NULL )
       return;

    papszMetadata = poDriver->GetMetadata();
    if( !CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATE, FALSE ) )
	{
	printf( "Driver %s does not support Create() method.\n" );
        return;
	}
 	int x = 40;
	int y = 40;
    GDALDataset* m_gdalDataSet = poDriver->Create( "T:\\foo.bmp", x, y, 3,
GDT_Byte, NULL);
	if ( m_gdalDataSet == NULL )
		return;

	GDALRasterBand *poBand = m_gdalDataSet->GetRasterBand(1);
	if ( poBand == NULL )
		return;

	unsigned char* value = (unsigned char*)malloc(x*y);
	memset(value,255,x*y);
	CPLErr err = poBand->RasterIO( GF_Write, 0, 0, x, y, value, x, y,
GDT_Byte, 0, 0 );    
	free(value);
	if ( err != CE_None )
	{
		return;
	}
	m_gdalDataSet->FlushCache();
	GDALClose(m_gdalDataSet);
};

as output (in stdout) I have :
ERROR 3: Can't write block with X offset 0 and Y offset 0
ERROR 3: Can't write block with X offset 0 and Y offset 1
ERROR 3: Can't write block with X offset 0 and Y offset 2
ERROR 3: Can't write block with X offset 0 and Y offset 3
(...)
ERROR 3: Can't write block with X offset 0 and Y offset 33
ERROR 3: Can't write block with X offset 0 and Y offset 34

RasterIO returns CE_None and the created file is wrong.

can you help me with this problem ?
I tried to check the gdal code when debugging, but I'm lost.

Thanks in advance,

Stephane



More information about the Gdal-dev mailing list