本文整理汇总了C#中System.Windows.Media.DrawingGroup.Freeze方法的典型用法代码示例。如果您正苦于以下问题:C# DrawingGroup.Freeze方法的具体用法?C# DrawingGroup.Freeze怎么用?C# DrawingGroup.Freeze使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.DrawingGroup
的用法示例。
在下文中一共展示了DrawingGroup.Freeze方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectionRectVisual
/// <summary>
/// Construct new SelectionRectVisual object for the given rectangle
/// </summary>
public SelectionRectVisual(Point firstPointP, Point secondPointP, double zoomP)
{
DrawingGroup drawing = new DrawingGroup();
DrawingContext context = drawing.Open();
context.DrawRectangle(Brushes.White, null, new Rect(-1, -1, 3, 3));
context.DrawRectangle(Brushes.Black, null, new Rect(0.25, -1, 0.5, 3));
context.Close();
drawing.Freeze();
// Create a drawing brush that tiles the unit square from the drawing created above.
// The size of the viewport and the rotation angle will be updated as we use the
// dashed pen.
DrawingBrush drawingBrush = new DrawingBrush(drawing);
drawingBrush.ViewportUnits = BrushMappingMode.Absolute;
drawingBrush.Viewport = new Rect(0, 0, _dashRepeatLength, _dashRepeatLength);
drawingBrush.ViewboxUnits = BrushMappingMode.Absolute;
drawingBrush.Viewbox = new Rect(0, 0, 1, 1);
drawingBrush.Stretch = Stretch.Uniform;
drawingBrush.TileMode = TileMode.Tile;
// Store the drawing brush and a copy that's rotated by 90 degrees.
_horizontalDashBrush = drawingBrush;
_verticalDashBrush = drawingBrush.Clone();
_verticalDashBrush.Transform = new RotateTransform(90);
this._firstPoint = firstPointP;
this._secondPoint = secondPointP;
this._zoom = zoomP;
_visualForRect = new DrawingVisual();
this.AddVisualChild(_visualForRect);
this.AddLogicalChild(_visualForRect);
}
示例2: drawArrow
public void drawArrow(Point x, Point y, Pen pen, Color penColor)
{
DrawingGroup drawing = new DrawingGroup();
drawing.Children.Add(new ImageDrawing(bmp, new Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight)));
drawing.Children.Add(new GeometryDrawing(pen.Brush, pen, Drawing.makeArrowGeometry(x, y, pen.Thickness)));
drawing.ClipGeometry = new RectangleGeometry(new Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight));
drawing.Freeze();
var image = new Image { Source = new DrawingImage(drawing) };
var bitmap = new RenderTargetBitmap(bmp.PixelWidth, bmp.PixelHeight, 96, 96, PixelFormats.Pbgra32);
image.Arrange(new Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight));
bitmap.Render(image);
bmp = BitmapFactory.ConvertToPbgra32Format(bitmap);
}
示例3: OnSelectPicture
private void OnSelectPicture()
{
var openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Все файлы изображений|*.bmp; *.png; *.jpeg; *.jpg; *.svg|BMP Файлы|*.bmp|PNG Файлы|*.png|JPEG Файлы|*.jpeg|JPG Файлы|*.jpg|SVG Файлы|*.svg";
if (openFileDialog.ShowDialog().Value)
{
// TODO: ограничить размер файла
_newImage = true;
_sourceName = openFileDialog.FileName;
_imageSource = null;
_isVectorImage = VectorGraphicExtensions.Contains(Path.GetExtension(_sourceName));
if (_isVectorImage)
{
using (FileSvgReader reader = new FileSvgReader(_settings))
_drawing = reader.Read(_sourceName);
_drawing.Freeze();
}
UpdateImage();
}
}
示例4: drawStamp
public void drawStamp(Point p, BitmapSource stamp, int size)
{
int stampWidth, stampHeight;
if (stamp.PixelHeight > stamp.PixelWidth) {
stampHeight = size;
stampWidth = (int)((double)size * ((double)stamp.PixelWidth / (double)stamp.PixelHeight));
} else {
stampHeight = (int)((double)size * ((double)stamp.PixelHeight / (double)stamp.PixelWidth));
stampWidth = size;
}
DrawingGroup drawing = new DrawingGroup();
drawing.Children.Add(new ImageDrawing(bmp, new Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight)));
drawing.Children.Add(new ImageDrawing(stamp, new Rect(p.X - stampWidth / 2, p.Y - stampHeight / 2, stampWidth, stampHeight)));
drawing.ClipGeometry = new RectangleGeometry(new Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight));
drawing.Freeze();
var image = new Image { Source = new DrawingImage(drawing) };
var bitmap = new RenderTargetBitmap(bmp.PixelWidth, bmp.PixelHeight, 96, 96, PixelFormats.Pbgra32);
image.Arrange(new Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight));
bitmap.Render(image);
bmp = BitmapFactory.ConvertToPbgra32Format(bitmap);
}
示例5: OnWorkerDoWork
private void OnWorkerDoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = (BackgroundWorker)sender;
_wpfSettings.IncludeRuntime = _options.IncludeRuntime;
_wpfSettings.TextAsGeometry = _options.TextAsGeometry;
_fileReader.UseFrameXamlWriter = !_options.UseCustomXamlWriter;
if (_options.GeneralWpf)
{
_fileReader.SaveXaml = _options.SaveXaml;
_fileReader.SaveZaml = _options.SaveZaml;
}
else
{
_fileReader.SaveXaml = false;
_fileReader.SaveZaml = false;
}
_drawing = _fileReader.Read(_sourceFile, _outputInfoDir);
if (_drawing == null)
{
e.Result = "Failed";
return;
}
if (_options.GenerateImage)
{
_fileReader.SaveImage(_sourceFile, _outputInfoDir,
_options.EncoderType);
_imageFile = _fileReader.ImageFile;
}
_xamlFile = _fileReader.XamlFile;
_zamlFile = _fileReader.ZamlFile;
if (_drawing.CanFreeze)
{
_drawing.Freeze();
}
e.Result = "Successful";
}
示例6: getTacticAt
public override ImageSource getTacticAt(int time)
{
if (staticTactics.ContainsKey(time)) {
if (staticTactics[time].isClone) {
return getTacticAt(staticTactics[time].cloneOriginalTime);
} else {
if (hasSampleLine) {
DrawingGroup drawing = new DrawingGroup();
drawing.Children.Add(new ImageDrawing(staticTactics[time].map.getImage(), new Rect(0, 0, 1024, 1024)));
drawing.Children.Add(new GeometryDrawing(samplePen.Brush, samplePen, new LineGeometry(sample.Key, sample.Value)));
drawing.ClipGeometry = new RectangleGeometry(new Rect(0, 0, 1024, 1024));
drawing.Freeze();
return new DrawingImage(drawing);
} else if (hasSampleArrow) {
Pen pen = this.samplePen.Clone();
pen.EndLineCap = PenLineCap.Triangle;
DrawingGroup drawing = new DrawingGroup();
drawing.Children.Add(new ImageDrawing(staticTactics[time].map.getImage(), new Rect(0, 0, 1024, 1024)));
drawing.Children.Add(new GeometryDrawing(pen.Brush, pen, Drawing.makeArrowGeometry(sample.Key, sample.Value, pen.Thickness)));
drawing.ClipGeometry = new RectangleGeometry(new Rect(0, 0, 1024, 1024));
drawing.Freeze();
return new DrawingImage(drawing);
} else if (sampleStamp.size != 0) {
int stampWidth, stampHeight;
if (sampleStamp.stamp.PixelHeight > sampleStamp.stamp.PixelWidth) {
stampHeight = sampleStamp.size;
stampWidth = (int)((double)sampleStamp.size * ((double)sampleStamp.stamp.PixelWidth / (double)sampleStamp.stamp.PixelHeight));
} else {
stampHeight = (int)((double)sampleStamp.size * ((double)sampleStamp.stamp.PixelHeight / (double)sampleStamp.stamp.PixelWidth));
stampWidth = sampleStamp.size;
}
DrawingGroup drawing = new DrawingGroup();
drawing.Children.Add(new ImageDrawing(staticTactics[time].map.getImage(), new Rect(0, 0, 1024, 1024)));
drawing.Children.Add(new ImageDrawing(sampleStamp.stamp, new Rect(sampleStamp.p.X - stampWidth / 2, sampleStamp.p.Y - stampHeight / 2, stampWidth, stampHeight)));
drawing.ClipGeometry = new RectangleGeometry(new Rect(0, 0, 1024, 1024));
drawing.Freeze();
return new DrawingImage(drawing);
} else {
return staticTactics[time].map.getImage();
}
}
} else {
return clearTactic;
}
}
示例7: DrawTiles
private void DrawTiles(System.Windows.Media.DrawingContext dc)
{
TilesWideObject = (int)(this.ActualWidth / 64) + 1;
TilesHighObject = (int)(this.ActualHeight / 64) + 1;
int startX = (int)CurrentPointObject.X - (TilesWideObject / 2);
int startY = (int)CurrentPointObject.Y - (TilesHighObject / 2);
if (startX < 0)
startX = 0;
if (startY < 0)
startY = 0;
int endX = startX + TilesWideObject;
int endY = startY + TilesHighObject;
if (endX > GameWorldObject.GameMapWidth)
{
endX = GameWorldObject.GameMapWidth;
startX = endX - TilesWideObject;
}
else if (startX < 0)
{
startX = 0;
endX = TilesWideObject;
}
if (endY > GameWorldObject.GameMapHeight)
{
endY = GameWorldObject.GameMapHeight;
startY = endY - TilesHighObject;
}
else if (startY < 0)
{
startY = 0;
endY = TilesHighObject;
}
int CountX = 0;
int CountY = 0;
DrawingGroup dg = new DrawingGroup();
for (int x = startX; x < endX; x++)
{
for (int y = startY; y < endY; y++)
{
dg.Children.Add(
new ImageDrawing(_mapTiles[GameWorldObject.GameMap[x, y].GraphicsTile.TileStartPoint],
new Rect(CountX * 64, CountY * 64, 64, 64)
));
dg.Children.Add(
new GeometryDrawing(
null,
new Pen(
new SolidColorBrush(
Color.FromRgb(255, 0, 20)), .3),
new RectangleGeometry(
new Rect(CountX * 64, CountY * 64, 64, 64)
)
)
);
#if DEBUG
if (x % 5 == 0 && y % 5 == 0)
{
FormattedText text = new FormattedText("X:" + x + " Y:" + y,
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
new System.Windows.Media.Typeface("arial"),
12,
new SolidColorBrush(Color.FromRgb(255, 0, 20)));
Geometry geometry = text.BuildGeometry(new Point(CountX * 64, CountY * 64));
GeometryDrawing gd = new GeometryDrawing(new SolidColorBrush(Color.FromRgb(255, 0, 20)), new Pen(), geometry);
dg.Children.Add(gd);
}
#endif
CountY++;
}
CountY = 0;
CountX++;
}
dg.Freeze();
dc.DrawDrawing(dg);
}
示例8: InkCanvasSelectionAdorner
/// <summary>
/// Constructor
/// </summary>
/// <param name="adornedElement">The adorned InkCanvas</param>
internal InkCanvasSelectionAdorner(UIElement adornedElement)
: base(adornedElement)
{
Debug.Assert(adornedElement is InkCanvasInnerCanvas,
"InkCanvasSelectionAdorner only should be used by InkCanvas internally");
// Initialize the internal data.
_adornerBorderPen = new Pen(Brushes.Black, 1.0);
DoubleCollection dashes = new DoubleCollection( );
dashes.Add(4.5);
dashes.Add(4.5);
_adornerBorderPen.DashStyle = new DashStyle(dashes, 2.25);
_adornerBorderPen.DashCap = PenLineCap.Flat;
_adornerBorderPen.Freeze();
_adornerPenBrush = new Pen(new SolidColorBrush(Color.FromRgb(132, 146, 222)), 1);
_adornerPenBrush.Freeze();
_adornerFillBrush = new LinearGradientBrush( Color.FromRgb(240, 242, 255), //start color
Color.FromRgb(180, 207, 248), //end color
45f //angle
);
_adornerFillBrush.Freeze();
// Create a hatch pen
DrawingGroup hatchDG = new DrawingGroup( );
DrawingContext dc = null;
try
{
dc = hatchDG.Open( );
dc.DrawRectangle(
Brushes.Transparent,
null,
new Rect(0.0, 0.0, 1f, 1f));
Pen squareCapPen = new Pen(Brushes.Black, LineThickness);
squareCapPen.StartLineCap = PenLineCap.Square;
squareCapPen.EndLineCap = PenLineCap.Square;
dc.DrawLine(squareCapPen,
new Point(1f, 0f), new Point(0f, 1f));
}
finally
{
if ( dc != null )
{
dc.Close( );
}
}
hatchDG.Freeze();
DrawingBrush tileBrush = new DrawingBrush(hatchDG);
tileBrush.TileMode = TileMode.Tile;
tileBrush.Viewport = new Rect(0, 0, HatchBorderMargin, HatchBorderMargin);
tileBrush.ViewportUnits = BrushMappingMode.Absolute;
tileBrush.Freeze();
_hatchPen = new Pen(tileBrush, HatchBorderMargin);
_hatchPen.Freeze();
_elementsBounds = new List<Rect>();
_strokesBounds = Rect.Empty;
}
示例9: GetDrawingHelper
private DrawingGroup GetDrawingHelper()
{
// Printing an HWND requires UIPermissionWindow.AllWindows to give out its pixels.
SecurityHelper.DemandUIWindowPermission();
DrawingGroup drawingGroup = null;
if(_hwnd.Handle != IntPtr.Zero && UnsafeNativeMethods.IsWindow(_hwnd))
{
NativeMethods.RECT rc = new NativeMethods.RECT();
SafeNativeMethods.GetWindowRect(_hwnd, ref rc);
int width = rc.right - rc.left;
int height = rc.bottom - rc.top;
HandleRef hdcScreen = new HandleRef(this, UnsafeNativeMethods.GetDC(new HandleRef(this, IntPtr.Zero)));
if(hdcScreen.Handle != IntPtr.Zero)
{
HandleRef hdcBitmap = new HandleRef(this, IntPtr.Zero);
HandleRef hBitmap = new HandleRef(this, IntPtr.Zero);
try
{
hdcBitmap = new HandleRef(this, UnsafeNativeMethods.CriticalCreateCompatibleDC(hdcScreen));
if(hdcBitmap.Handle != IntPtr.Zero)
{
hBitmap = new HandleRef(this, UnsafeNativeMethods.CriticalCreateCompatibleBitmap(hdcScreen, width, height));
if(hBitmap.Handle != IntPtr.Zero)
{
// Select the bitmap into the DC so that we draw to it.
IntPtr hOldBitmap = UnsafeNativeMethods.CriticalSelectObject(hdcBitmap, hBitmap.Handle);
try
{
// Clear the bitmap to white (so we don't waste toner printing a black bitmap something fails).
NativeMethods.RECT rcPaint = new NativeMethods.RECT(0,0,width, height);
IntPtr hbrWhite = UnsafeNativeMethods.CriticalGetStockObject(NativeMethods.WHITE_BRUSH);
UnsafeNativeMethods.CriticalFillRect(hdcBitmap.Handle, ref rcPaint, hbrWhite);
// First try to use the PrintWindow API.
bool result = UnsafeNativeMethods.CriticalPrintWindow(_hwnd, hdcBitmap, 0);
if(result == false)
{
// Fall back to sending a WM_PRINT message to the window.
//
// Note: there are known cases where WM_PRINT is not implemented
// to provide visual parity with WM_PAINT. However, since the
// GetDrawing method is virtual, the derived class can override
// this default implementation and provide a better implementation.
UnsafeNativeMethods.SendMessage(_hwnd.Handle, WindowMessage.WM_PRINT, hdcBitmap.Handle, (IntPtr) (NativeMethods.PRF_CHILDREN | NativeMethods.PRF_CLIENT | NativeMethods.PRF_ERASEBKGND | NativeMethods.PRF_NONCLIENT));
}
else
{
// There is a know issue where calling PrintWindow on a window will
// clear all dirty regions (but since it is redirected, the screen
// won't be updated). As a result we can leave unpainted pixels on
// the screen if PrintWindow is called when the window was dirty.
//
// To fix this, we just force the child window to repaint.
//
UnsafeNativeMethods.CriticalRedrawWindow(_hwnd, IntPtr.Zero, IntPtr.Zero, NativeMethods.RDW_INVALIDATE | NativeMethods.RDW_ALLCHILDREN);
}
// Create a DrawingGroup that only contains an ImageDrawing that wraps the bitmap.
drawingGroup = new DrawingGroup();
System.Windows.Media.Imaging.BitmapSource bitmapSource = Imaging.CriticalCreateBitmapSourceFromHBitmap(hBitmap.Handle, IntPtr.Zero, Int32Rect.Empty, null, WICBitmapAlphaChannelOption.WICBitmapIgnoreAlpha);
Rect rectElement = new Rect(RenderSize);
drawingGroup.Children.Add(new ImageDrawing(bitmapSource, rectElement));
drawingGroup.Freeze();
}
finally
{
// Put the old bitmap back into the DC.
UnsafeNativeMethods.CriticalSelectObject(hdcBitmap, hOldBitmap);
}
}
}
}
finally
{
UnsafeNativeMethods.ReleaseDC(new HandleRef(this, IntPtr.Zero), hdcScreen);
hdcScreen = new HandleRef(null, IntPtr.Zero);
if(hBitmap.Handle != IntPtr.Zero)
{
UnsafeNativeMethods.DeleteObject(hBitmap);
hBitmap = new HandleRef(this, IntPtr.Zero);
}
if(hdcBitmap.Handle != IntPtr.Zero)
{
UnsafeNativeMethods.CriticalDeleteDC(hdcBitmap);
hdcBitmap = new HandleRef(this, IntPtr.Zero);
}
}
}
}
return drawingGroup;
}
示例10: HeliosVisualContainerEditor
public HeliosVisualContainerEditor()
{
Focusable = true;
_view = new HeliosVisualView();
_view.IgnoreHidden = true;
_view.DisplayRotation = false;
AddVisualChild(_view);
SelectedItems = new HeliosVisualCollection();
_zoomCalibration = new CalibrationPointCollectionDouble(-4d, 0.25d, 4d, 4d);
_zoomCalibration.Add(new CalibrationPointDouble(0d, 1d));
SelectedItems.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedItems_CollectionChanged);
DrawingGroup checkerGroup = new DrawingGroup();
checkerGroup.Children.Add(new GeometryDrawing(Brushes.White, null, new RectangleGeometry(new Rect(0, 0, 100, 100))));
DrawingGroup grayGroup = new DrawingGroup();
grayGroup.Children.Add(new GeometryDrawing(Brushes.LightGray, null, new RectangleGeometry(new Rect(0, 0, 50, 50))));
grayGroup.Children.Add(new GeometryDrawing(Brushes.LightGray, null, new RectangleGeometry(new Rect(50, 50, 50, 50))));
checkerGroup.Children.Add(grayGroup);
checkerGroup.Freeze();
_checkerBrush = new DrawingBrush(checkerGroup);
_checkerBrush.Viewport = new Rect(0, 0, 10, 10);
_checkerBrush.ViewportUnits = BrushMappingMode.Absolute;
_checkerBrush.TileMode = TileMode.Tile;
_checkerBrush.Freeze();
}
示例11: CreateImage
public static DrawingImage CreateImage(PointPattern[] pointPatterns, Size size, Color color)
{
if (pointPatterns == null)
throw new Exception("You must provide a gesture before trying to generate a thumbnail");
DrawingGroup drawingGroup = new DrawingGroup();
for (int i = 0; i < pointPatterns.Length; i++)
{
PathGeometry pathGeometry = new PathGeometry();
color.A = (byte)(0xFF - i * 0x55);
SolidColorBrush brush = new SolidColorBrush(color);
Pen drawingPen = new Pen(brush, 3 + i * 2) { StartLineCap = PenLineCap.Round, EndLineCap = PenLineCap.Round };
if (pointPatterns[i].Points == null) return null;
for (int j = 0; j < pointPatterns[i].Points.Count; j++)
{
if (pointPatterns[i].Points[j].Count == 1)
{
Geometry ellipse = new EllipseGeometry(new Point(size.Width * j + size.Width / 2, size.Height / 2),
drawingPen.Thickness / 2, drawingPen.Thickness / 2);
pathGeometry.AddGeometry(ellipse);
continue;
}
StreamGeometry sg = new StreamGeometry { FillRule = FillRule.EvenOdd };
using (StreamGeometryContext sgc = sg.Open())
{
// Create new size object accounting for pen width
Size szeAdjusted = new Size(size.Width - drawingPen.Thickness - 1,
(size.Height - drawingPen.Thickness - 1));
Size scaledSize;
Point[] scaledPoints = ScaleGesture(pointPatterns[i].Points[j], szeAdjusted.Width - 10, szeAdjusted.Height - 10,
out scaledSize);
// Define size that will mark the offset to center the gesture
double iLeftOffset = (size.Width / 2) - (scaledSize.Width / 2);
double iTopOffset = (size.Height / 2) - (scaledSize.Height / 2);
Vector sizOffset = new Vector(iLeftOffset + j * size.Width, iTopOffset);
sgc.BeginFigure(Point.Add(scaledPoints[0], sizOffset), false, false);
foreach (Point p in scaledPoints)
{
sgc.LineTo(Point.Add(p, sizOffset), true, true);
}
DrawArrow(sgc, scaledPoints, sizOffset, drawingPen.Thickness);
}
sg.Freeze();
pathGeometry.AddGeometry(sg);
}
pathGeometry.Freeze();
GeometryDrawing drawing = new GeometryDrawing(null, drawingPen, pathGeometry);
drawing.Freeze();
drawingGroup.Children.Add(drawing);
}
// myPath.Data = sg;
drawingGroup.Freeze();
DrawingImage drawingImage = new DrawingImage(drawingGroup);
drawingImage.Freeze();
return drawingImage;
}
示例12: Render
void Render(int points, int size)
{
var sw = Stopwatch.StartNew();
var r = new Random();
var pen = new Pen(Brushes.DeepPink, 2);
pen.Freeze();
Trace.WriteLine("after freeze: " + sw.GetElapsedAndRestart().TotalMilliseconds);
var d = new DrawingGroup();
using (var cx = d.Open())
{
for (int i = 0; i < points; i++)
{
cx.DrawLine(pen, new Point(r.Next(0, 50), r.Next(0, 50)), new Point(r.Next(0, 50), r.Next(0, 50)));
}
}
d.Freeze();
var dv = new DrawingVisual();
using (var cx = dv.RenderOpen())
{
cx.DrawDrawing(d);
//for (int i = 0; i < points; i++)
//{
// cx.DrawLine(pen, new Point(r.Next(0, 50), r.Next(0, 50)), new Point(r.Next(0, 50), r.Next(0, 50)));
//}
}
Trace.WriteLine("after draw: " + sw.GetElapsedAndRestart().TotalMilliseconds);
var trb = new RenderTargetBitmap(size, size, 96, 96, PixelFormats.Pbgra32);
trb.Render(dv);
Trace.WriteLine("after render: " + sw.GetElapsedAndRestart().TotalMilliseconds);
var x = trb.GetPixels();
Trace.WriteLine("after get pixels: " + sw.GetElapsedAndRestart().TotalMilliseconds);
//trb.Save([email protected]"C:\temp\shit\{size}.png");
}
示例13: pingTimer_Tick
private void pingTimer_Tick(object sender, EventArgs e)
{
if (pingAnimationPhase == 6) {
pingTimer.IsEnabled = false;
if (menuShowGrid.IsChecked) {
gridBox.Source = new BitmapImage(new Uri(@"pack://application:,,,/Resources/grid.png", UriKind.Absolute));
} else {
gridBox.Source = null;
}
return;
}
if (pingAnimationAlpha == 250 || pingAnimationAlpha == 0) {
pingAnimationPhase += 1;
}
if (pingAnimationPhase % 2 == 0) {
pingAnimationAlpha += 10;
} else {
pingAnimationAlpha -= 10;
}
BitmapImage img;
if (menuShowGrid.IsChecked) {
img = new BitmapImage(new Uri(@"pack://application:,,,/Resources/grid.png", UriKind.Absolute));
} else {
img = new BitmapImage(new Uri(@"pack://application:,,,/Resources/clearTactics.png", UriKind.Absolute));
}
Pen pen = new Pen(new SolidColorBrush(Color.FromArgb(pingAnimationAlpha, 255, 102, 0)), 4);
Point p1 = new Point(pingArea.Key * img.PixelWidth / 10, pingArea.Value * img.PixelWidth / 10);
Point p2 = new Point((pingArea.Key + 1) * img.PixelWidth / 10 + 1, pingArea.Value * img.PixelWidth / 10);
Point p3 = new Point((pingArea.Key + 1) * img.PixelWidth / 10 + 1, (pingArea.Value + 1) * img.PixelWidth / 10 + 1);
Point p4 = new Point(pingArea.Key * img.PixelWidth / 10, (pingArea.Value + 1) * img.PixelWidth / 10 + 1);
DrawingGroup drawing = new DrawingGroup();
drawing.Children.Add(new ImageDrawing(img, new Rect(0, 0, img.PixelWidth, img.PixelHeight)));
drawing.Children.Add(new GeometryDrawing(pen.Brush, pen, new LineGeometry(p1, p2)));
drawing.Children.Add(new GeometryDrawing(pen.Brush, pen, new LineGeometry(p2, p3)));
drawing.Children.Add(new GeometryDrawing(pen.Brush, pen, new LineGeometry(p3, p4)));
drawing.Children.Add(new GeometryDrawing(pen.Brush, pen, new LineGeometry(p4, p1)));
drawing.ClipGeometry = new RectangleGeometry(new Rect(0, 0, img.PixelWidth, img.PixelHeight));
drawing.Freeze();
gridBox.Source = new DrawingImage(drawing);
}
示例14: SensorSkeletonFrameReady
private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
if (isRecording)
{
DateTime Time = DateTime.Now;
Skeleton[] skeletons = new Skeleton[0];
float[] floor = new float[4];
using (Microsoft.Kinect.SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
{
if (skeletonFrame != null)
{
skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
skeletonFrame.CopySkeletonDataTo(skeletons);
floor[0] = skeletonFrame.FloorClipPlane.Item1;
floor[1] = skeletonFrame.FloorClipPlane.Item2;
floor[2] = skeletonFrame.FloorClipPlane.Item3;
floor[3] = skeletonFrame.FloorClipPlane.Item4;
}
}
foreach (Skeleton skel in skeletons)
{
if (skel.TrackingState == SkeletonTrackingState.Tracked)
{
KinectLib.SkeletonFrame frame = new KinectLib.SkeletonFrame();
frame.Date = Time;
frame.SkeletonId = skel.TrackingId;
frame.Nodes = new List<SkeletonNode>();
frame.X = skel.Position.X;
frame.Y = skel.Position.Y;
frame.Z = skel.Position.Z;
frame.Floor = floor;
foreach (Joint joint in skel.Joints)
{
SkeletonNode node = new SkeletonNode();
node.NodeType = (int)joint.JointType;
node.X = joint.Position.X;
node.Y = joint.Position.Y;
node.Z = joint.Position.Z;
frame.Nodes.Add(node);
}
Frames.Add(frame);
Skeleton DisplaySkeleton = skel;
Joint Crotch = DisplaySkeleton.Joints.First(j => j.JointType == JointType.HipCenter);
if (Crotch != null)
{
DrawingGroup DrawingGroup = new DrawingGroup();
using (DrawingContext Context = DrawingGroup.Open())
{
Double CrotchDisplayX = image1.Width / 2;
Double CrotchDisplayY = image1.Height / 2;
foreach (Joint Node in DisplaySkeleton.Joints)
{
double X = (Node.Position.X - Crotch.Position.X) / 2.5 * image1.Width + CrotchDisplayX;
double Y = (-Node.Position.Y + Crotch.Position.Y) / 2.5 * image1.Height + CrotchDisplayY;
Context.DrawEllipse(Brushes.Wheat, new Pen(Brushes.Navy, 2), new Point(X, Y), 7, 7);
}
}
DrawingGroup.Freeze();
Dispatcher.Invoke(new Action(() => { image1.Source = new DrawingImage(DrawingGroup); }));
}
}
}
}
}
示例15: getTacticAt
public override ImageSource getTacticAt(int time)
{
DrawingGroup resultDraw = new DrawingGroup();
DrawingContext dc = resultDraw.Open();
resultDraw.ClipGeometry = new RectangleGeometry(new Rect(0, 0, clearTactic.PixelWidth, clearTactic.PixelHeight));
dc.DrawImage(clearTactic, new Rect(0, 0, clearTactic.PixelWidth, clearTactic.PixelHeight));
Pen pen = new Pen(brush, iconsSize / 2);
Pen linePen = new Pen(brush, iconsSize / 25);
foreach (StaticIcon staticon in staticIcons) {
BitmapImage icon = staticon.getImage();
dc.DrawImage(icon, new Rect(staticon.position.X - iconsSize / 2, staticon.position.Y - iconsSize / 2, iconsSize, (iconsSize * icon.Height) / icon.Width));
if (selectedStaticIcon.Contains(staticon)) {
dc.DrawGeometry(brush, linePen, makeRectangleGeometry(new Rect(staticon.position.X - iconsSize / 2 - 2, staticon.position.Y - iconsSize / 2 - 2, iconsSize + 2, (iconsSize * icon.Height) / icon.Width + 2)));
}
}
foreach (DynamicTank tank in dynamicTanks) {
BitmapSource icon;
Point pos = getTankPosition(tank, time);
double iconWidth = 0, iconHeight = 0;
if (TankIcon == DisplayTankIcon.tanktype) {
if (tank.killTime < time) {
icon = icons.getTankIcon(tank.tank.type, tank.isAlly).getAliveImage();
} else {
icon = icons.getTankIcon(tank.tank.type, tank.isAlly).getDeadImage();
}
int roundTime = (int)(Math.Ceiling((float)time / 30.0) * 30.0);
BitmapSource actionIcon = null;
if (tank.actions.ContainsKey(roundTime)) {
actionIcon = icons.getDynamicIcon(tank.actions[roundTime]).getImage();
}
if (icon.Height < icon.Width) {
iconWidth = iconsSize;
iconHeight = (iconsSize * icon.Height) / icon.Width;
} else {
iconWidth = (iconsSize * icon.Width) / icon.Height;
iconHeight = iconsSize;
}
dc.DrawImage(icon, new Rect(pos.X - iconWidth / 2, pos.Y - iconHeight / 2, iconWidth, iconHeight));
if (selectedDynamicTank.Contains(tank)) {
dc.DrawGeometry(brush, linePen, makeRectangleGeometry(new Rect(pos.X - iconWidth / 2 - 2, pos.Y - iconHeight / 2 - 2, iconWidth + 2, iconHeight + 2)));
}
if (actionIcon != null) {
dc.DrawImage(actionIcon, new Rect(pos.X - iconsSize, pos.Y - iconsSize, iconsSize * 2, (iconsSize * actionIcon.Height * 2) / actionIcon.Width));
}
} else {
if (tank.killTime < time) {
icon = tank.tank.getImage();
if (icon.Height < icon.Width) {
iconWidth = iconsSize * 1.8;
iconHeight = (iconsSize * icon.Height) / icon.Width * 1.8;
} else {
iconWidth = (iconsSize * icon.Width) / icon.Height;
iconHeight = iconsSize;
}
dc.DrawImage(icon, new Rect(pos.X - iconWidth / 2, pos.Y - iconHeight / 2, iconWidth, iconHeight));
if (selectedDynamicTank.Contains(tank)) {
dc.DrawGeometry(brush, linePen, makeRectangleGeometry(new Rect(pos.X - iconWidth / 2 - 2, pos.Y - iconHeight / 2 - 2, iconWidth + 2, iconHeight + 2)));
}
}
}
if ((ShowPlayerName && tank.name != "") || ShowTankName) {
string text = "";
if ((ShowPlayerName && tank.name != "") && ShowTankName) {
text = tank.name + " (" + tank.tank.name + ")";
} else if (ShowPlayerName && tank.name != "") {
text = tank.name;
} else if (ShowTankName) {
text = tank.tank.name;
}
FormattedText ftxt = new FormattedText(text, System.Globalization.CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface(new FontFamily("Tahoma"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), iconsSize / 2, brush);
dc.DrawText(ftxt, new Point(pos.X - ftxt.WidthIncludingTrailingWhitespace / 2 - 5, pos.Y + iconHeight / 2));
}
}
dc.Close();
resultDraw.Freeze();
return new DrawingImage(resultDraw);
}