本文整理汇总了C#中System.Windows.Media.DrawingContext.Close方法的典型用法代码示例。如果您正苦于以下问题:C# DrawingContext.Close方法的具体用法?C# DrawingContext.Close怎么用?C# DrawingContext.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.DrawingContext
的用法示例。
在下文中一共展示了DrawingContext.Close方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateBitmap
public void CreateBitmap()
{
int width = 100;
int height = 100;
int dpi = 96;
Tracing.Log(">> CreateBitmap");
var thread = new Thread(new ThreadStart(() =>
{
Tracing.Log(">> CreateBitmap - Thread start; creating drawing visual");
//Dispatcher.Invoke(new Action(() => {
_drawingVisual = new DrawingVisual();
_drawingContext = _drawingVisual.RenderOpen();
//}));
Tracing.Log(">> CreateBitmap - Drawing to context");
_drawingContext.DrawRectangle(new SolidColorBrush(Colors.HotPink), new Pen(), new Rect(0, 0, 50, 50));
_drawingContext.DrawRectangle(new SolidColorBrush(Colors.Blue), new Pen(), new Rect(50, 0, 50, 50));
_drawingContext.DrawRectangle(new SolidColorBrush(Colors.Orange), new Pen(), new Rect(0, 50, 50, 50));
_drawingContext.DrawRectangle(new SolidColorBrush(Colors.DarkRed), new Pen(), new Rect(50, 50, 50, 50));
_drawingContext.Close();
Tracing.Log(">> CreateBitmap - Finished drawing; creating render target bitmap");
_bitmap = new RenderTargetBitmap(width, height, dpi, dpi, PixelFormats.Default);
_bitmap.Render(_drawingVisual);
Tracing.Log(">> CreateBitmap - Finished work");
_bitmap.Freeze();
}));
//thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
示例2: RenderDiagram
public DrawingVisual RenderDiagram(SequenceDiagram sequenceDiagram)
{
_nodeMiddlePoints = new Dictionary<Guid, double>();
_diagramSize = new Size(0.5, 80.5);
var canvas = new DrawingVisual();
_context = canvas.RenderOpen();
DrawAllNodes(sequenceDiagram);
DrawAllDiagramElements(sequenceDiagram);
DrawVerticalLines(sequenceDiagram);
_context.Close();
return canvas;
}
示例3: DrawingGeometry
private void DrawingGeometry(DrawingContext drawingContext, double value, double maxValue, double radiusX, double radiusY, double thickness, double padding)
{
if (Math.Abs(value - maxValue) > 0.00001)
{
var brush = value < WarnValue ? WarnBrush : NormalBrush;
drawingContext.DrawEllipse(null, new Pen(new SolidColorBrush(Color.FromRgb(0xdd, 0xdf, 0xe1)), thickness), _centerPoint, radiusX, radiusY);
drawingContext.DrawGeometry(brush, new Pen(), GetGeometry(value, maxValue, radiusX, thickness, padding));
var formatWords = new FormattedText(_percentString,
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
SuccessRateTypeface,
SuccessRateFontSize,
brush);
var startPoint = new Point(_centerPoint.X - formatWords.Width / 2, _centerPoint.Y - formatWords.Height / 2);
drawingContext.DrawText(formatWords, startPoint);
}
else
{
drawingContext.DrawEllipse(null, new Pen(NormalBrush, thickness), _centerPoint, radiusX, radiusY);
var formatWords = new FormattedText("100%",
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
SuccessRateTypeface,
SuccessRateFontSize,
NormalBrush);
var startPoint = new Point(_centerPoint.X - formatWords.Width / 2, _centerPoint.Y - formatWords.Height / 2);
drawingContext.DrawText(formatWords, startPoint);
}
drawingContext.Close();
}
示例4: DrawingGeometry
private void DrawingGeometry(DrawingContext drawingContext, double value, double maxValue, double radiusX, double radiusY, double thickness, double padding)
{
if (value != maxValue) {
SolidColorBrush brush;
if (value < WarnValue) {
brush = WarnBrush;
} else {
brush = NormalBrush;
}
drawingContext.DrawEllipse(null, new Pen(WarnBrush, thickness), centerPoint, radiusX, radiusY);
//drawingContext.DrawEllipse(null, new Pen(new SolidColorBrush(Color.FromRgb(0xdd, 0xdf, 0xe1)), thickness), centerPoint, radiusX, radiusY);
drawingContext.DrawGeometry(NormalBrush, new Pen(), GetGeometry(value, maxValue, radiusX, radiusY, thickness, 0));
FormattedText formatWords = new FormattedText(percentString,
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
SuccessRateTypeface,
SuccessRateFontSize,
TextBrush);
Point startPoint = new Point(centerPoint.X - formatWords.Width / 2, centerPoint.Y - formatWords.Height / 2);
drawingContext.DrawText(formatWords, startPoint);
} else {
drawingContext.DrawEllipse(null, new Pen(NormalBrush, thickness), centerPoint, radiusX, radiusY);
FormattedText formatWords = new FormattedText("0 s",
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
SuccessRateTypeface,
SuccessRateFontSize,
TextBrush);
Point startPoint = new Point(centerPoint.X - formatWords.Width / 2, centerPoint.Y - formatWords.Height / 2);
drawingContext.DrawText(formatWords, startPoint);
}
drawingContext.Close();
}
示例5: ComposeCore
protected virtual void ComposeCore(DrawingContext drawingContext, DrawingVisual visual)
{
if (this.Visible == false)
{
drawingContext.Close();
return;
}
//draw rounded rectangle
RectangleGeometry roundedRect = new RectangleGeometry();
int tempWidth = (int)Width;
int tempHeight = (int)Height;
//@TODO(Ben) please double check this is recomended behaviour and insert guidance url here
roundedRect.Rect = new Rect(new Point(0.5, 0.5), new Point(tempWidth + 0.5, tempHeight + 0.5));
//roundedRect.RadiusX = Configurations.CornerRadius;
//roundedRect.RadiusY = Configurations.CornerRadius;
//@TODO(Ben) extract this into a common place, don't recreate.
//@TODO(Ben) Move this numbers to constant fields in configurations
DropShadowEffect shadowEffect = new DropShadowEffect();
shadowEffect.BlurRadius = Configurations.BlurRadius;
shadowEffect.Color = Configurations.SelectionColor;
shadowEffect.Direction = Configurations.Direction;
shadowEffect.ShadowDepth = Configurations.ShadowDepth;
shadowEffect.Opacity = Configurations.Opacity;
drawingContext.DrawGeometry(Configurations.RectWhite, Configurations.BorderPen, roundedRect);
//@TODO(Ben) If previewSelected != true remove the effect, don't just make it white
if (this.PreviewSelected == true)
{
drawingContext.DrawGeometry(Configurations.RectWhite, Configurations.SelectionBorderPen, roundedRect);
visual.Effect = shadowEffect;
}
else
{
drawingContext.DrawGeometry(Configurations.RectWhite, Configurations.BorderPen, roundedRect);
shadowEffect.Opacity = 0;
shadowEffect.Color = Configurations.SelectionColorWhite;
visual.Effect = shadowEffect;
}
if (partDisplayingMenu == NodePart.NorthEast)
{
//@TODO(Joy) Magic numbers, lalalala, magic numbers
//@TODO: XAMLify this
Rect newRect = new Rect(new Point(Width - 30, -20), new Size(50, 50));
}
else if (partDisplayingMenu == NodePart.PreviewNorthEast)
{
Point pt = this.previewBubble.RectPosition;
pt.Offset(this.previewBubble.Width - 30, -20);
Rect newRect = new Rect(pt, new Size(50, 50));
}
}
示例6: MovingText_execute
public void MovingText_execute()
{
switch (mode)
{
case "Links nach Rechts":
counter++;
textBox.Foreground = new SolidColorBrush(colors[counter % 360]);
if (Pos.X > -text.Width)
Pos.X--;
else Pos.X = 68;
break;
case "Rechts nach Links":
{
counter++;
textBox.Foreground = new SolidColorBrush(colors[counter % 360]);
if (Pos.X < 68)
Pos.X++;
else Pos.X = -text.Width;
break;
}
case "Oben/Unten":
counter++;
textBox.Foreground = new SolidColorBrush(colors[counter % 360]);
if (Pos.Y < 42)
Pos.Y++;
else Pos.Y= -text.Height;
break;
}
renderTargetBitmap.Clear();
using( monitor.GetBitmapContext())
{
//string time = DateTime.Now.Hour + " : " + DateTime.Now.Minute + " : " + DateTime.Now.Second;
text = new FormattedText(textBox.Text,
new CultureInfo("de-de"),
FlowDirection.LeftToRight,
new Typeface(textBox.FontFamily, FontStyles.Normal, textBox.FontWeight, new FontStretch()),
textBox.FontSize,
textBox.Foreground);
text.LineHeight = textBox.FontSize;
drawingContext = drawingVisual.RenderOpen();
drawingContext.DrawText(text, Pos);
drawingContext.Close();
renderTargetBitmap.Render(drawingVisual);
renderTargetBitmap.CopyPixels(new Int32Rect(0, 0, renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight),
monitor.BackBuffer, monitor.BackBufferStride * monitor.PixelHeight, monitor.BackBufferStride);
}
}
示例7: DrawBonesAndJoints
private void DrawBonesAndJoints(Skeleton skeleton, DrawingContext drawingContext)
{
float headloc = 0;
float LefthandlocY = 0;
float LefthandlocX = 0;
float RighthandlocY = 0;
float RighthandlocX = 0;
int movementcount = 0;
// Render Joints
foreach (Joint joint in skeleton.Joints)
{
Brush drawBrush = null;
if (joint.TrackingState == JointTrackingState.Tracked)
{
drawBrush = this.trackedJointBrush;
}
else if (joint.TrackingState == JointTrackingState.Inferred)
{
drawBrush = this.inferredJointBrush;
}
if (drawBrush != null)
{
drawingContext.DrawEllipse(drawBrush, null, this.SkeletonPointToScreen(joint.Position), JointThickness, JointThickness);
}
//find head location
if (joint.JointType == JointType.Head)
{
headloc = joint.Position.Y;
}
//find left hand location
if (joint.JointType == JointType.HandLeft)
{
LefthandlocY = joint.Position.Y;
LefthandlocX = joint.Position.X;
}
//find right hand location
if (joint.JointType == JointType.HandRight)
{
RighthandlocY = joint.Position.Y;
RighthandlocX = joint.Position.X;
}
}
//see if left hand is above head
if (LefthandlocY > headloc && movementcount == 0)
{
Indicator.Background = new SolidColorBrush(Colors.Green);
SendKeys.SendWait("{LEFT}");
movementcount = movementcount + 1;
}
// see if right hand is above head
if (RighthandlocY > headloc && movementcount == 0)
{
SendKeys.SendWait("{RIGHT}");
movementcount = movementcount + 1;
}
// see if hands are crossed
if (LefthandlocX > RighthandlocX && movementcount == 0)
{
SendKeys.SendWait("z");
CrossIndicator.Background = new SolidColorBrush(Colors.Purple);
movementcount = movementcount + 1;
}
drawingContext.Close();
}
示例8: MenuItem_Redo_Click
/// <summary>
/// Unlimited redo
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MenuItem_Redo_Click(object sender, RoutedEventArgs e)
{
int count = bitmapHistory.Count;
if (count > 0) {
bitmap.Clear();
drawContext = drawVisual.RenderOpen();
drawContext.DrawImage(bitmapHistory.Pop(),
new Rect(0, 0, imageWidth, imageHeight));
drawContext.Close();
bitmap.Render(drawVisual);
}
}
示例9: MenuItem_Open_Click
private void MenuItem_Open_Click(object sender, RoutedEventArgs e)
{
var dlg = new OpenFileDialog();
dlg.Filter = "PNG(*.png)|*.png";
if (dlg.ShowDialog() == true) {
using (FileStream stream = new FileStream(dlg.FileName,
FileMode.Open, FileAccess.Read)) {
try {
BitmapImage src = new BitmapImage();
src.BeginInit();
src.StreamSource = stream;
src.CacheOption = BitmapCacheOption.OnLoad;
src.EndInit();
//image1.Source = src;
bitmapHistory.Push((RenderTargetBitmap)bitmap.Clone());
bitmap.Clear();
drawContext = drawVisual.RenderOpen();
drawContext.DrawImage(src,
new Rect(0, 0, imageWidth, imageHeight));
drawContext.Close();
bitmap.Render(drawVisual);
} catch (Exception ex) {
MessageBox.Show(ex.ToString(), "Exception",
MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}
示例10: image_MouseMove
/// <summary>
/// Preview drawing
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void image_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed) {
Point pt = e.GetPosition(image1);
Point rpt = ConvertPoint(pt);
previewBitmap.Clear();
drawContext = drawVisual.RenderOpen();
Pen penDraw = new Pen(brush, penThick);
switch (drawType) {
case DrawType.Line:
drawContext.DrawLine(penDraw, ptLast, rpt);
break;
case DrawType.Box:
drawContext.DrawRectangle(fillBrush, penDraw, new Rect(ptLast, rpt));
break;
case DrawType.Circle: {
double r = CalcDist(ptLast, rpt);
drawContext.DrawEllipse(fillBrush, penDraw, ptLast, r, r);
}
break;
default:
break;
}
drawContext.Close();
previewBitmap.Render(drawVisual);
}
}