public void Filter(IPixelBlock pPixelBlock) { try { IPixelBlock3 pPixelBlock3 = (IPixelBlock3)pPixelBlock; byte[] lookup = new byte[8] { 128, 64, 32, 16, 8, 4, 2, 1 }; //get number of bands int plane = pPixelBlock.Planes; //loop through each band for (int i = 0; i < plane; i++) { //get nodata mask array byte[] outputArray = (byte[])pPixelBlock3.get_NoDataMaskByRef(i); //loop through each pixel in the pixelblock and do calculation for (int x = 0; x < pPixelBlock.Width; x++) { for (int y = 0; y < pPixelBlock.Height; y++) { //get index in the nodata mask byte array int ind = x + y * (pPixelBlock.Width); //get nodata mask byte byte nd = outputArray[ind / 8]; //get pixel value and check if it is nodata object tempVal = pPixelBlock3.GetVal(i, x, y); if (tempVal != null) //not nodata pixel { //convert pixel value to int and compare with nodata range int curVal = Convert.ToInt32(tempVal); if (curVal >= minNodataValue && curVal <= maxNodataValue) { outputArray[ind / 8] = (byte)(nd & ~lookup[ind % 8]); } } } } //set nodata mask array pPixelBlock3.set_NoDataMask(i, outputArray); } } catch (Exception e) { Console.WriteLine(e.Message); } }