『公告』 预祝您龙年大吉,万事如意, 过节期间, 大家如需数据服务,请拨打400 或直接添加客服微信,再祝大家龙年,心想事成。
关注我们 新浪 腾讯

ArcGIS Engine 10 开发手册(8-8)示例:改变栅格数据像素的值

ArcGIS Engine 10 开发手册(8-8)示例:改变栅格数据像素的值
本文通过代码演示如何改变栅格数据像素的值。

    本文通过代码演示如何改变栅格数据像素的值。


    示例代码

public void ChangeRasterValue (IRasterDataset2 pRasterDatset)

 

{

 

  IRaster2 pRaster2 = pRasterDatset.CreateFullRaster () as IRaster2;

 

  IPnt pPntBlock = new PntClass ();

  pPntBlock.X = 128;

 

  pPntBlock.Y = 128;

 

  IRasterCursor pRasterCursor = pRaster2.CreateCursorEx (pPntBlock);

  IRasterEdit pRasterEdit = pRaster2 as IRasterEdit;

 

  if (pRasterEdit.CanEdit ())

 

  {

 

    IRasterBandCollection pBands = pRasterDatset as IRasterBandCollection;

 

    IPixelBlock3 pPixelblock3 = null;

    int pBlockwidth = 0;

 

    int pBlockheight = 0;

    System.Array pixels;

    IPnt pPnt = null;

    object pValue;

 

    long pBandCount = pBands.Count;

 

    //获取Nodata

 

    //IRasterProps pRasterPro = pRaster2 as IRasterProps;

 

    //object pNodata = pRasterPro.NoDataValue;

 

    do

 

    {

 

      pPixelblock3 = pRasterCursor.PixelBlock as IPixelBlock3;

      pBlockwidth = pPixelblock3.Width;

 

      pBlockheight = pPixelblock3.Height;

 

      for (int k = 0; k < pBandCount; k++)

 

      {

 

        pixels = (System.Array) pPixelblock3.get_PixelData (k);

        for (int i = 0; i < pBlockwidth; i++)

 

        {

 

          for (int j = 0; j < pBlockheight; j++)

 

          {

 

            pValue = pixels.GetValue (i, j);

            if (Convert.ToInt32 (pValue) == 0)

 

            {

 

              pixels.SetValue (Convert.ToByte (50), i, j);

 

            }

 

          }

 

        }

 

        pPixelblock3.set_PixelData (k, pixels);

 

      }

 

      pPnt = pRasterCursor.TopLeft;

      pRasterEdit.Write (pPnt,(IPixelBlock) pPixelblock3);

 

    }

 

    while (pRasterCursor.Next ());

 

    System.Runtime.InteropServices.Marshal.ReleaseComObject (pRasterEdit);

 

  }

 

}

    处理结果

    原始影像图:

 

 

 

    处理后的影像图:

 

      京ICP备08100627号-22 京公网安备 11010802030428号