本文整理汇总了C#中System.Windows.Media.DrawingContext.PushOpacityMask方法的典型用法代码示例。如果您正苦于以下问题:C# DrawingContext.PushOpacityMask方法的具体用法?C# DrawingContext.PushOpacityMask怎么用?C# DrawingContext.PushOpacityMask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.DrawingContext
的用法示例。
在下文中一共展示了DrawingContext.PushOpacityMask方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnRender
protected override void OnRender(DrawingContext drawingContext) {
// draw everything except the reflection
base.OnRender(drawingContext);
// set opacity
drawingContext.PushOpacityMask(opacityMask);
reflection.Visual = Child;
var group = new TransformGroup();
if (Child.RenderTransform is TransformGroup) {
foreach (var child in ((TransformGroup)Child.RenderTransform).Children) {
group.Children.Add(child);
}
}
else {
group.Children.Add(Child.RenderTransform);
}
scaleTransform.CenterY = (ActualHeight / 1.5) + ((ActualHeight / 1.5) / 4);
scaleTransform.CenterX = ActualWidth / 2;
group.Children.Add(scaleTransform);
reflection.Transform = group;
// draw the reflection
drawingContext.DrawRectangle(
reflection, null,
new Rect(0, ActualHeight / 1.5, ActualWidth, ActualHeight / 3));
// cleanup
drawingContext.Pop();
}
示例2: Render
public void Render(DrawingContext dc, Point location, Brush tint, int tileIndex)
{
var dstRect = new Rect(location, new Size(TileWidth, TileHeight));
dc.PushOpacityMask(new ImageBrush(_tiles[tileIndex]));
dc.DrawRectangle(tint, null, dstRect);
dc.Pop();
}
示例3: OnRender
protected override void OnRender(DrawingContext drawingContext)
{
// draw everything except the reflection
base.OnRender(drawingContext);
// set opacity
drawingContext.PushOpacityMask(_opacityMask);
drawingContext.PushOpacity(0.4);
// set reflection parameters based on content size
_reflection.Visual = Child;
// draw the reflection
drawingContext.DrawRectangle(_reflection, null, new Rect(0, ActualHeight + _gap, ActualWidth, ActualHeight));
// cleanup
drawingContext.Pop();
drawingContext.Pop();
}
示例4: ApplyFilter
protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
{
var gradientStops = new GradientStopCollection();
gradientStops.Add(new GradientStop(SWMColor.FromArgb(0, 0, 0, 0), 0));
gradientStops.Add(new GradientStop(SWMColor.FromArgb(0, 0, 0, 0), 0.5));
gradientStops.Add(new GradientStop(SWMColor.FromArgb(180, 0, 0, 0), 1.3));
gradientStops.Add(new GradientStop(SWMColor.FromArgb(230, 0, 0, 0), 1.7));
var brush = new RadialGradientBrush(gradientStops)
{
GradientOrigin = new Point(0.5, 0.5),
Center = new Point(0.5, 0.45),
RadiusX = 0.5,
RadiusY = 0.5
};
dc.DrawImage(source.InnerBitmap, new Rect(0, 0, width, height));
dc.PushOpacityMask(brush);
dc.DrawRectangle(new SolidColorBrush(SWMColors.Black), null, new Rect(0, 0, width, height));
dc.Pop();
}
示例5: OnRender
protected override void OnRender(DrawingContext drawingContext)
{
// draw everything except the reflection
base.OnRender(drawingContext);
// set opacity
drawingContext.PushOpacityMask(_opacityMask);
drawingContext.PushOpacity(0.3);
// set reflection parameters based on content size
_reflection.Visual = Child;
((ScaleTransform)_reflection.Transform).CenterY = 3 * ActualHeight / 4;
((ScaleTransform)_reflection.Transform).CenterX = ActualWidth / 2;
// draw the reflection
drawingContext.DrawRectangle(
_reflection, null,
new Rect(0, ActualHeight / 2, ActualWidth, ActualHeight / 2));
// cleanup
drawingContext.Pop();
drawingContext.Pop();
}
示例6: ApplyFilter
/// <summary>
/// Applies the <see cref="ShinyFloorFilter" /> to the specified <paramref name="source"/>.
/// </summary>
/// <param name="source">The source image.</param>
/// <param name="dc"></param>
/// <param name="width"></param>
/// <param name="height"></param>
protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
{
// First, draw reflected image with an opacity mask.
int reflectionHeight = (int)(source.Height * (ReflectionPercentage / 100.0f));
dc.PushTransform(new TransformGroup
{
Children = new TransformCollection
{
new ScaleTransform {ScaleY = -1},
new TranslateTransform {Y = GetReflectionOffsetY(source) + reflectionHeight}
}
});
dc.PushOpacityMask(new LinearGradientBrush(
Colors.Transparent,
Color.FromArgb((byte)(255.0f * (ReflectionOpacity / 100.0f)), 0, 0, 0),
new Point(0, 0),
new Point(0, 1)));
dc.DrawImage(new CroppedBitmap(source.InnerBitmap, new Int32Rect(0, source.Height - reflectionHeight, source.Width, reflectionHeight)),
new Rect(0, 0, source.Width, reflectionHeight));
dc.Pop();
dc.Pop();
// Draw original image.
dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height));
}
示例7: OnRender
protected override void OnRender(DrawingContext drawingContext)
{
var child = Child;
if (child == null)
{
return;
}
if (m_brush == null)
{
return;
}
var renderSize = RenderSize;
var childRenderSize = child.RenderSize;
var reflectionSize = ReflectionSize;
var reflectionSeparation = ReflectionSeparation;
var matrix = Matrix.Identity;
matrix.Scale(1,-1);
matrix.Translate (0, childRenderSize.Height + reflectionSize + reflectionSeparation);
m_transform.Matrix = matrix;
drawingContext.PushTransform (m_transform);
drawingContext.PushOpacityMask (m_opacityMask);
var rectangle = new Rect(
0,
0,
renderSize.Width,
reflectionSize
);
drawingContext.DrawRectangle (
m_brush,
null,
rectangle
);
drawingContext.Pop();
drawingContext.Pop();
}
示例8: OnRender
protected override void OnRender(DrawingContext drawingContext)
{
// Draw non-reflection controls
base.OnRender(drawingContext);
double halfHeight = ActualHeight / 2;
// Create fading opacity mask
drawingContext.PushOpacityMask(opacityMask);
drawingContext.PushOpacity(0.15);
// Create the reflection mirror transform.
reflection.Visual = Child;
((ScaleTransform)reflection.Transform).CenterY = ActualHeight * 3/4;
((ScaleTransform)reflection.Transform).CenterX = ActualWidth / 2;
// Draw the reflection visual with opacity mask applied
drawingContext.DrawRectangle(
reflection, null,
new Rect(0, halfHeight, ActualWidth, halfHeight));
// Remove opacity masks for next drawing
drawingContext.Pop();
drawingContext.Pop();
}
示例9: CreatePageVisual
protected virtual void CreatePageVisual(Rect pageBounds, DrawingVisual source, bool isFooterPage, DrawingContext drawingContext)
{
drawingContext.DrawRectangle(null, FramePen, new Rect { X = FrameRect.X, Y = FrameRect.Y, Width = FrameRect.Width, Height = FrameRect.Height });
var offsetX = PageMargins.Left - pageBounds.X - 1;
var offsetY = PageMargins.Top - pageBounds.Y;
drawingContext.PushTransform(new TranslateTransform(offsetX, offsetY + HeaderHeight));
var pg = new Rect(new Point(pageBounds.X, pageBounds.Y), new Size(pageBounds.Width, pageBounds.Height));
drawingContext.PushClip(new RectangleGeometry(pg));
drawingContext.PushOpacityMask(Brushes.White);
drawingContext.DrawDrawing(source.Drawing);
}
示例10: OnRender
protected override void OnRender(DrawingContext drawingContext)
{
base.OnRender(drawingContext);
drawingContext.PushOpacityMask(ReflectionMask);
drawingContext.PushOpacity(ReflectionOpacity);
_mReflection.Visual = Child;
((ScaleTransform)_mReflection.Transform).CenterY = 3 * ActualHeight / 4;
((ScaleTransform)_mReflection.Transform).CenterX = ActualWidth / 2;
drawingContext.DrawRectangle(_mReflection, null, new Rect(0, ActualHeight / 2, ActualWidth, ActualHeight / 2));
drawingContext.Pop();
drawingContext.Pop();
}
示例11: Antialiasing
//DepthImagePixel[] depthPixels, byte[] colorPixels,DepthImageFormat depthFormat, ColorImageFormat colorFormat)
public void Antialiasing(DrawingContext drawingContext)
{
// do our processing outside of the using block
// so that we return resources to the kinect as soon as possible
_sensor.CoordinateMapper.MapDepthFrameToColorFrame(
_sensor.DepthStream.Format,
_depthPixels,
_sensor.ColorStream.Format,
_colorCoordinates);
Array.Clear(_greenScreenPixelData, 0, _greenScreenPixelData.Length);
_borderCounter = 0;
// loop over each row and column of the depth
for (int y = 0; y < _depthHeight; ++y)
{
for (int x = 0; x < _depthWidth; ++x)
{
// calculate index into depth array
int depthIndex = x + (y * _depthWidth);
DepthImagePixel depthPixel = _depthPixels[depthIndex];
int player = depthPixel.PlayerIndex;
int depthDist = depthPixel.Depth;
// if we're tracking a player for the current pixel, do green screen
if (player > 0 && (depthDist > 400 && depthDist < 3500))
{
//found = true;
// retrieve the depth to color mapping for the current depth pixel
ColorImagePoint colorImagePoint = _colorCoordinates[depthIndex];
// scale color coordinates to depth resolution
int colorInDepthX = colorImagePoint.X / _colorToDepthDivisor;
int colorInDepthY = colorImagePoint.Y / _colorToDepthDivisor;
// make sure the depth pixel maps to a valid point in color space
// check y > 0 and y < depthHeight to make sure we don't write outside of the array
// check x > 0 instead of >= 0 since to fill gaps we set opaque current pixel plus the one to the left
// because of how the sensor works it is more correct to do it this way than to set to the right
if (colorInDepthX > 0 && colorInDepthX < _depthWidth && colorInDepthY >= 0 && colorInDepthY < _depthHeight)
{
// calculate index into the green screen pixel array
int greenScreenIndex = colorInDepthX + (colorInDepthY * _depthWidth);
if (_antialiasing)
{
AddBorderPixels(greenScreenIndex);
_greenScreenPixelData[greenScreenIndex] = OpaquePoint;
}
else
{
_greenScreenPixelData[greenScreenIndex] = OpaquePoint;
_greenScreenPixelData[greenScreenIndex - 1] = OpaquePoint;
}
}
}
}
}
if (_antialiasing)
{
Antialiasing();
//HidePixels();
}
// do our processing outside of the using block
// so that we return resources to the kinect as soon as possible
// Write the pixel data into our bitmap
_colorBitmap.WritePixels(
new Int32Rect(0, 0, _colorBitmap.PixelWidth, _colorBitmap.PixelHeight),
_colorPixels,
_colorBitmap.PixelWidth * sizeof(int),
0);
if (_playerOpacityMaskImage == null)
{
_playerOpacityMaskImage = new WriteableBitmap(
_depthWidth,
_depthHeight,
96,
96,
PixelFormats.Bgra32,
null);
}
_playerOpacityMaskImage.WritePixels(
new Int32Rect(0, 0, _depthWidth, _depthHeight),
_greenScreenPixelData,
_depthWidth * ((_playerOpacityMaskImage.Format.BitsPerPixel) / 8),
0);
drawingContext.PushOpacityMask(new ImageBrush { ImageSource = _playerOpacityMaskImage});
drawingContext.DrawImage(_colorBitmap, new Rect(0, 0, ActualWidth, ActualHeight));
}