本文整理汇总了C#中System.Windows.Media.Imaging.WriteableBitmap.AddDirtyRect方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.AddDirtyRect方法的具体用法?C# WriteableBitmap.AddDirtyRect怎么用?C# WriteableBitmap.AddDirtyRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.WriteableBitmap
的用法示例。
在下文中一共展示了WriteableBitmap.AddDirtyRect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawPixel
// The DrawPixel method updates the WriteableBitmap by using
// unsafe code to write a pixel into the back buffer.
static void DrawPixel(MouseEventArgs e)
{
int column = (int)e.GetPosition(i).X;
int row = (int)e.GetPosition(i).Y;
try{
// Reserve the back buffer for updates.
writeableBitmap.Lock();
unsafe
{
// Get a pointer to the back buffer.
IntPtr pBackBuffer = writeableBitmap.BackBuffer;
// Find the address of the pixel to draw.
pBackBuffer += row * writeableBitmap.BackBufferStride;
pBackBuffer += column * 4;
// Compute the pixel's color.
int color_data = 255 << 16; // R
color_data |= 128 << 8; // G
color_data |= 255 << 0; // B
// Assign the color data to the pixel.
*((int*) pBackBuffer) = color_data;
}
// Specify the area of the bitmap that changed.
writeableBitmap.AddDirtyRect(new Int32Rect(column, row, 1, 1));
}
finally{
// Release the back buffer and make it available for display.
writeableBitmap.Unlock();
}
}