[gdal-dev] how to read the color value of particular pixel

Chaitanya kumar CH chaitanya.ch at gmail.com
Mon Jul 12 08:26:37 EDT 2010


Vajram,

You should check if the object ct, is null after band.GetRasterColorTable().
Perhaps there is no color table for D:\pr.IMG

On Mon, Jul 12, 2010 at 5:37 PM, mail2vajram <mail2vajram at gmail.com> wrote:

>
> i want to know how to read the color value of particular pixel. and
> previously i used the following code to read the color table.but now it
> throws null reference exception.why?. My objective is to prepare the Rater
> legend control based on pixel values.
>
>
>  Gdal.AllRegister();
>            Dataset ds = Gdal.Open(@"D:\pr.IMG", Access.GA_ReadOnly);
>            Band band = ds.GetRasterBand(1);
>            ColorTable ct = band.GetRasterColorTable();
>            ArrayList arraylist = new ArrayList();
>            for (int i = 0; i < ct.GetCount(); i++)
>            {
>                ColorEntry ce = ct.GetColorEntry(i);
>                Color cr1 = Color.FromArgb(ce.c4, ce.c1, ce.c2, ce.c3);
>                arraylist.Add(cr1);
>            }
> --
> View this message in context:
> http://osgeo-org.1803224.n2.nabble.com/how-to-read-the-color-value-of-particular-pixel-tp5282620p5282620.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.
/tʃaɪθənjə/ /kʊmɑr/
+91-9494447584
17.2416N 80.1426E
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20100712/1986481b/attachment.html


More information about the gdal-dev mailing list