思路:需要获取指定的像元,然后找到可以对该像元进行编辑的接口,设定改后像元的值重新写入该像元。
需要用到的接口IPixelBlock3 IRasterEdit。
IRasterEdit接口里面的Write方法允许对相应的值进行修改(针对的是像元块PixelBlock);
IRasterEdit
//updateRastervalue
private void button3_Click(object sender, EventArgs e)
{
IRasterLayer lyr = axMapControl1.Map.get_Layer(0) as IRasterLayer;
IRaster rst = lyr.Raster;//可以跳转到IRasterEdit
IPnt pnt = new PntClass();
pnt.X = 1;
pnt.Y = 1;
IPixelBlock pk = rst.CreatePixelBlock(pnt);//创建一个像元块
IPnt tpl = new PntClass();
tpl.X = column;
tpl.Y = row;
IRasterEdit rstedit = rst as IRasterEdit;
rstedit.Write(tpl,pk);
//使用IPixelBlock3中的get_PixelBlock()方法来获取像元块的值(返回的是一个数组)
IPixelBlock3 pk3 = pk as IPixelBlock3;
Array arr = pk3.get_PixelData(0);//0表示波段索引
//数组array的setvalue方法可以设定数组内的值
arr.SetValue(Convert.ToInt16(85), 0, 0);
//设定完成后再传回到IPixelBlock3的Pixeldata
pk3.set_PixelData(0, arr);
rstedit.Write(tpl,pk3 as IPixelBlock);
MessageBox.Show("修改完成");
axMapControl1.Refresh();
}