Open the workspace (File) where the raster file is located, obtain all its bands, and access each band.
You can use the computestatsandhist () function to calculate a histogram or statistical information in a band.
(Large data volumes may take a long time)
Iworkspacefactory workspacefactory = new rasterworkspacefactory ();
Iworkspace;
Workspace = workspacefactory. openfromfile (filepath, 0 );
Irasterworkspace rastwork = (irasterworkspace) Workspace;
Irasterdataset rastdataset = rastwork. openrasterdataset (pathbox. Text. substring (pathbox. Text. lastindexof ("\") + 1 ));
Irasterdataset2 RD2 = rastdataset as irasterdataset2;
Iraster raster = rd2.createfullraster ();
Irasterbandcollection rb= (irasterbandcollection) raster;
For (INT I = 0; I <RBC. Count; I ++)
{
Irasterband RB = RBC. item (I );
Bool tmpbool;
RB. hasstatistics (Out tmpbool );
If (! Tmpbool)
RB. computestatsandhist ();
Irasterhistogram RH = RB. histogram;
Irasterstatistics rs = RB. Statistics;
}