本文整理汇总了C#中IRaster.CreatePixelBlock方法的典型用法代码示例。如果您正苦于以下问题:C# IRaster.CreatePixelBlock方法的具体用法?C# IRaster.CreatePixelBlock怎么用?C# IRaster.CreatePixelBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRaster
的用法示例。
在下文中一共展示了IRaster.CreatePixelBlock方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetValues
/// <summary>
/// Get the pixel values in a region of the input raster.
/// </summary>
/// <param name="tlCorner"></param>
/// <param name="brCorner"></param>
/// <param name="raster"></param>
/// <returns></returns>
public static double[,] GetValues(Position tlCorner, Position brCorner, IRaster raster)
{
int colCount = brCorner.Column - tlCorner.Column + 1;
int rowCount = brCorner.Row - tlCorner.Row + 1;
IPnt regionSize = new PntClass();
regionSize.SetCoords(colCount, rowCount);
IPixelBlock pixelBlock = raster.CreatePixelBlock(regionSize);
IPnt tl = new PntClass();
tl.SetCoords(tlCorner.Column, tlCorner.Row);
raster.Read(tl, pixelBlock);
double[,] values = new double[colCount, rowCount];
for (int x = 0; x < colCount; x++)
{
for (int y = 0; y < rowCount; y++)
{
values[x, y] = Convert.ToDouble(pixelBlock.GetVal(0, x, y));
}
}
return values;
}
示例2: WriteEdits
/// <summary>
/// Write edits to the input raster.
/// </summary>
/// <param name="raster">Raster of raster layer to be edited.</param>
/// <param name="edits">Pixel collection that contains edited pixels.</param>
private static void WriteEdits(IRaster raster, PixelCollection edits)
{
IRasterProps rasterProps = (IRasterProps)raster;
int minRow = rasterProps.Height - 1;
int maxRow = 0;
int minCol = rasterProps.Width - 1;
int maxCol = 0;
for (int i = 0; i < edits.Count; i++)
{
#region Get the extent of the edition region
Position cellPos = edits[i].Position;
if (cellPos.Row > maxRow)
{
maxRow = cellPos.Row;
}
if (cellPos.Row < minRow)
{
minRow = cellPos.Row;
}
if (cellPos.Column > maxCol)
{
maxCol = cellPos.Column;
}
if (cellPos.Column < minCol)
{
minCol = cellPos.Column;
}
#endregion
}
IPnt pos = new PntClass();
pos.SetCoords(maxCol - minCol + 1, maxRow - minRow + 1);
IPixelBlock pixelBlock = raster.CreatePixelBlock(pos);
pos.SetCoords(minCol, minRow);
raster.Read(pos, pixelBlock);
// Set new values
IPixelBlock3 pixelBlock3 = (IPixelBlock3)pixelBlock;
Array pixels = (Array)pixelBlock3.get_PixelData(0);
for (int i = 0; i < edits.Count; i++)
{
object value = null;
Raster.CSharpValue2PixelValue(edits[i].NewValue, rasterProps.PixelType, out value);
pixels.SetValue(value,
edits[i].Position.Column - minCol,
edits[i].Position.Row - minRow);
}
pixelBlock3.set_PixelData(0, (System.Object)pixels);
IRasterEdit rasterEdit = (IRasterEdit)raster;
rasterEdit.Write(pos, (IPixelBlock)pixelBlock3);
}
示例3: GetValue
/// <summary>
/// Gets value of pixel at the specified position.
/// </summary>
/// <param name="pos"></param>
/// <param name="raster"></param>
/// <returns></returns>
public static double GetValue(Position pos, IRaster raster)
{
IPnt regionSize = new PntClass();
regionSize.SetCoords(1, 1);
IPixelBlock pixelBlock = raster.CreatePixelBlock(regionSize);
IPnt tl = new PntClass();
tl.SetCoords(pos.Column, pos.Row);
raster.Read(tl, pixelBlock);
return Convert.ToDouble(pixelBlock.GetVal(0, 0, 0));
}