[gdal-dev] Saving 16 bit image

Chaitanya kumar CH chaitanya.ch at gmail.com
Thu Jul 21 09:03:10 EDT 2011


pavkiz,

You are using GDT_Byte in the RasterIO function call. If you want to write
the date with 16bit depth you need to use GDT_Int16 or GDT_UInt16.

Check the translation with the GDAL utility gdal_translate [1] with the -ot
option.

[1]: http://www.gdal.org/gdal_translate.html

On Thu, Jul 21, 2011 at 6:16 PM, el_inca <pavkiz at mail.ru> wrote:

> Hi,
> Can anybody help me with saving TIFF images? I need to save 8 bit image to
> 16 bit image.
> Raster data is keeping in Byte array.
> When i save from 8 bit to 8 bit it works good.
> But when i save from 8 to 16 bit Gdal creates an image, that i can read
> after with this library, but not with another program that supports 16 bit
> images.
> I wrote a program that makes byte shift. So when shifting at 4 bytes in
> each
> image row it displays correctly.
> In documentation i have read that GDAL automatically translates data types.
>
> Image colorscheme is in RGB.
>
> Here is the part of code:
>
> GDALDataset *new_dataset;
>
> new_dataset=driver->Create(Filename,
>                                        image_size_x,
>                                        image_size_y,
>                                        poDataset->GetRasterCount(),
>                                        GDT_Int16,
>                               NULL);
>
> for (int raster=0;raster<poDataset->GetRasterCount();raster++)
>      {
>        GDALRasterBand *new_rasterband;
>        new_rasterband=new_dataset->GetRasterBand(raster+1);
>        for (int j=0;j&lt;image_size_y;j++)
>            {
>                Byte * scanline=new  Byte[image_size_x];
>                new_rasterband-&gt;RasterIO(GF_Write,
>                                             0,//start position in X
>                                                y,//start position in Y
>                                             image_size_x,
>                                             1,
>                                             scanline,
>                                             image_size_x,//buffer
>                                                     1,
>                                             GDT_Byte,
>                                             0,
>                                             0);
>              }
>   }
>
>
>
> --
> View this message in context:
> http://osgeo-org.1803224.n2.nabble.com/Saving-16-bit-image-tp6606613p6606613.html
> Sent from the GDAL - Dev mailing list archive at Nabble.com.
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>



-- 
Best regards,
Chaitanya kumar CH.

+91-9494447584
17.2416N 80.1426E
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110721/970bcbb4/attachment.html


More information about the gdal-dev mailing list