1 public void ChangePixelValue(double xMax, double xMin, double yMax, double yMin,double[,] PixelChanged)
2 {
3 IRaster pRaster = thisRasterLayer.Raster;
4 IRaster2 pRaster2 = pRaster as IRaster2;
5
6 //地图坐标转换为图中行列值
7 rowMax = pRaster2.ToPixelRow(yMin);
8 rowMin = pRaster2.ToPixelRow(yMax);
9 columnMin = pRaster2.ToPixelColumn(xMin);
10 columnMax = pRaster2.ToPixelColumn(xMax);
11
12 int Height = rowMax - rowMin + 1;
13 int Width = columnMax - columnMin + 1;
14
15 //按照需要的大小建立一个空的PixelBlock3
16 IPnt blocksize = new PntClass();
17 blocksize.SetCoords(Width, Height);
18
19 IPixelBlock3 pPixelBlock3 = pRaster.CreatePixelBlock(blocksize) as IPixelBlock3;
20
21 System.Array pixels = (System.Array)pPixelBlock3.get_PixelData(0);
22
23 //为新建的PixelBlock赋值
24 try
25 {
26 for (int i = 0; i < Height; i++)
27 {
28 for (int j = 0; j < Width; j++)
29 {
30 pixels.SetValue(Convert.ToByte(PixelChanged[i,j]), j, i);
31 }
32 }
33 }
34 catch (Exception ex)
35 {
36 MessageBox.Show(ex.Message);
37 }
38
39 //把像素值赋予新建的PixelBlock3
40 pPixelBlock3.set_PixelData(0, pixels);
41
42 //PixelBlock3应在的位置
43 blocksize.SetCoords(columnMin, rowMin);
44
45 //改变的像素值写入图层
46 IRasterEdit pRasterEdit = pRaster as IRasterEdit;
47 pRasterEdit.Write(blocksize, (IPixelBlock)pPixelBlock3);
48 pRasterEdit.Refresh();
49
50 System.Runtime.InteropServices.Marshal.ReleaseComObject(pRasterEdit);
51 }
//要保存的图层;
2 IRasterLayer pRasterLayer = axMapControl1.get_Layer(0) as IRasterLayer;
3 IRaster pRaster = pRasterLayer.Raster;
4 IRaster2 pRaster2 = pRaster as IRaster2;
5
6 ISaveAs pSaveAs = pRaster2 as ISaveAs;
7 pSaveAs.SaveAs(@"F:WorkDEM高程矩阵DEM高程矩阵inDebug渲染图层2.tif", null, "TIFF");
引用地址http://www.bubuko.com/infodetail-156921.html