Error of writing raster

Discussion created by dz3164244 on Jan 15, 2014
Latest reply on Jan 20, 2014 by dz3164244
Hi, I am writing a raster editor toolbar for interactive raster edition. It is almost done but I meet an error when I try to save the modification to file finally. My method is to copy the loaded raster and write the modification to the new file. Here is my code:
// Code to get the new raster
IRasterWorkspace newRasterWorkspace = (IRasterWorkspace)newWorkspace;
IRasterDataset newRasterDataset = newRasterWorkspace.OpenRasterDataset(System.IO.Path.GetFileNameWithoutExtension(saveFileDialog.FileName));
IRasterBandCollection newRasterBandCollection = (IRasterBandCollection)newRasterDataset;
IRasterBand newRasterBand = newRasterBandCollection.Item(0);
IRasterDataset2 newRasterDataset2 = (IRasterDataset2)newRasterBand.RasterDataset;
IRaster newRaster = newRasterDataset2.CreateFullRaster();
IRasterProps newRasterProp = (IRasterProps)newRaster;

// I omit some code to get the extent of modified region

IPnt pos = new PntClass();
pos.SetCoords(maxCol - minCol + 1, maxRow - minRow + 1);
IPixelBlock pixelBlock = newRaster.CreatePixelBlock(pos);
pos.SetCoords(minCol, minRow);
newRaster.Read(pos, pixelBlock);

// Set new values
IPixelBlock3 pixelBlock3 = (IPixelBlock3)pixelBlock;
Array pixels = (Array)pixelBlock3.get_PixelData(0);

for (int i = 0; i < Editor.EditRecord.Count; i++)
                         Editor.EditRecord[i].Position.Column - minCol,
                         Editor.EditRecord[i].Position.Row - minRow);

pixelBlock3.set_PixelData(0, (System.Object)pixels);
IRasterEdit newRasterEdit = (IRasterEdit)newRaster;

// Here comes the error:
newRasterEdit.Write(pos, (IPixelBlock)pixelBlock3);

I get the error information: Exception from HRESULT: 0x80041029. I do not find any information about the error code at ESRI help. The code looks very correct and I have no idea of the error.

btw, is there a way to directly save modification to the raster loaded at ArcMap?