I am trying to read a quickbird multispectral image which is having 16 bits pixel value each for red, green, blue and alpha component. I am reading its pixel values using gdal library but I am not getting the exact values of all 4 layers. I am getting very different image pixel values than the original and I dont know why it is coming so. please help me.........
Below is my code to read quickbird multispectral image....
GDALDataset *hd1;
GDALRasterBand *Rband, *Gband, *Bband, *Alphaband;
int widthMS,
int *Rbuffer, *Gbuffer, *Bbuffer, *Alphabuffer;
int i,j,k;
hd1 =(GDALDataset *)GDALOpen("G:\\images\\QB-multispectral-clipd.tif",GA_ReadOnly);
widthMS = hd1->GetRasterXSize();
heightMS = hd1->GetRasterYSize();
Rband = hd1->GetRasterBand(1);
Gband = hd1->GetRasterBand(2);
Bband = hd1->GetRasterBand(3);
Alphaband = hd1->GetRasterBand(4);
Rbuffer = (int*)CPLMalloc(sizeof(int)*widthMS*heightMS);
Gbuffer = (int*)CPLMalloc(sizeof(int)*widthMS*heightMS);
Bbuffer = (int*)CPLMalloc(sizeof(int)*widthMS*heightMS);
Alphabuffer = (int*)CPLMalloc(sizeof(int)*widthMS*heightMS);
Rband->RasterIO(GF_Read,0,0,widthMS,heightMS,Rbuffer,widthMS,heightMS,GDT_Int32,0,0);
Gband->RasterIO(GF_Read,0,0,widthMS,heightMS,Gbuffer,widthMS,heightMS,GDT_Int32,0,0);
Bband->RasterIO(GF_Read,0,0,widthMS,heightMS,Bbuffer,widthMS,heightMS,GDT_Int32,0,0);
Alphaband->RasterIO(GF_Read,0,0,widthMS,heightMS,Alphabuffer,widthMS,heightMS,GDT_Int32,0,0);
MSimage = gcnew System::Drawing::Bitmap(widthMS,heightMS,PixelFormat::Format32bppArgb);
k=0;
for (j=0;j<heightMS;j++)
{
for(i=0;i<widthMS;i++)
{
Color newclr = Color.FromArgb((unsigned char)(*(Alphabuffer+k)),(unsigned char)(*(Rbuffer+k)),(unsigned char)(*(Gbuffer+k)),(unsigned char)(*(Bbuffer+k)));
MSimage->SetPixel(i,j,newclr);
k++;
}
}
pictureBox2->Image = MSimage;