private void DrawFigure(Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args, Rect destRect, int zIndex, Point3D eyePos) { foreach (var plane in figure.Planes) { var p1 = Projections.GetPerspectiveProjection(plane.Points[plane.Points.Count - 1], zIndex, eyePos); var p2 = Projections.GetPerspectiveProjection(plane.Points[0], zIndex, eyePos); args.DrawingSession.DrawLine( new Vector2() { X = (float)(destRect.Width - (p1.X + destRect.Width / 2)), Y = (float)(p1.Y + destRect.Height / 2) }, new Vector2() { X = (float)(destRect.Width - (p2.X + destRect.Width / 2)), Y = (float)(p2.Y + destRect.Height / 2) }, Colors.Black ); for (int i = 0; i < plane.Points.Count - 1; i++) { p1 = Projections.GetPerspectiveProjection(plane.Points[i], zIndex, eyePos); p2 = Projections.GetPerspectiveProjection(plane.Points[i + 1], zIndex, eyePos); args.DrawingSession.DrawLine( new Vector2() { X = (float)(destRect.Width - (p1.X + destRect.Width / 2)), Y = (float)(p1.Y + destRect.Height / 2) }, new Vector2() { X = (float)(destRect.Width - (p2.X + destRect.Width / 2)), Y = (float)(p2.Y + destRect.Height / 2) }, Colors.Black ); } } }
unsafe private void AudioCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { if (this.m_AudioFrameOutputNode != null) { using (ICanvasBrush ybrush = new Microsoft.Graphics.Canvas.Brushes.CanvasSolidColorBrush(sender.Device, Windows.UI.Colors.Yellow)) using (ICanvasBrush bbrush = new Microsoft.Graphics.Canvas.Brushes.CanvasSolidColorBrush(sender.Device, Windows.UI.Colors.Red)) { // get a float pointer to the fftw in array float *fpin = (float *)pin; float halfHeight = (float)sender.ActualHeight / 2.0f; for (int i = 0; i < this.m_QuantumSamples.Length; i += 2) { int ii = i / 2; float f = this.m_QuantumSamples[i]; if ((ii) < sender.ActualWidth) { args.DrawingSession.DrawLine( (float)ii, (float)halfHeight, (float)ii, (float)halfHeight + (f * halfHeight), ybrush); } // put the float value in the real part (even index) // odd index is imaginery fpin[i] = f; } FFTWSharp.fftw.execute(fplan); float *fpout = (float *)pout; double maxmag = 100; double mult = this.m_AudioGraph.SamplesPerQuantum / maxmag; int halfi = 0; for (int i = 0; i < m_FFTSampleSize; i += 2) { double mag_k = 2.0 * Math.Sqrt(fpout[i] * fpout[i]) + (fpout[i + 1] * fpout[i + 1]) / (double)this.m_FFTSampleSize; double a_k = 20.0 * Math.Log10(mag_k); halfi = i / 2; args.DrawingSession.DrawLine(0, halfi * 2, (float)(a_k * mult), halfi * 2, bbrush); args.DrawingSession.DrawLine(0, halfi * 2 + 1, (float)(a_k * mult), halfi * 2 + 1, bbrush); } } //args.DrawingSession.DrawText("Samples Per Quantum = " + this.m_AudioGraph.SamplesPerQuantum, //0, 0, Windows.UI.Colors.Yellow); //args.DrawingSession.DrawText($"{this.m_FrameCount} " // + $"spq {this.m_AudioGraph.SamplesPerQuantum} " // + $"cap {this.m_Capacity} " // + $"abcap {this.m_abCap} " // + $"ablen {this.m_abLen}", 0, 0, Windows.UI.Colors.Yellow); //args.DrawingSession.DrawText($"bps {this.m_AudioGraph.EncodingProperties.BitsPerSample} " // + $"ch {this.m_AudioGraph.EncodingProperties.ChannelCount} " // + $"sr {this.m_AudioGraph.EncodingProperties.SampleRate}", 0, 18, Windows.UI.Colors.Yellow); } }
/// <summary> /// Draw the stuff on the canvas /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void CanvasControl_Draw( Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { Debug.WriteLine("canvas draw"); CanvasDrawingSession ds = args.DrawingSession; if (this.currentGraph != null) { this.currentGraph.Draw(args.DrawingSession); } else { Single x = (Single)(this.MainCanvas.ActualWidth / 2); Single y = (Single)(this.MainCanvas.ActualHeight / 2); CanvasTextFormat format = new CanvasTextFormat { FontSize = 30.0f, WordWrapping = CanvasWordWrapping.NoWrap }; CanvasTextLayout textLayout = new CanvasTextLayout(ds, "Nothing to see here.", format, 0.0f, 0.0f); Rect bounds = textLayout.LayoutBounds; Single newX = (Single)((this.MainCanvas.ActualWidth / 2) - (bounds.Width / 2)); Single newY = (Single)((this.MainCanvas.ActualHeight / 2) - (bounds.Height / 2)); ds.DrawTextLayout(textLayout, newX, newY, Colors.White); } }
protected void DrawString(Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs canvasArgs, CanvasTextFormat textFormat, double x, double y, string text, Color textColor, bool leftAligned, bool horizontallyCentered, bool verticallyCentered) { CanvasTextFormat ctf = new CanvasTextFormat() { FontSize = textFormat.FontSize, FontFamily = textFormat.FontFamily, HorizontalAlignment = CanvasHorizontalAlignment.Left, VerticalAlignment = CanvasVerticalAlignment.Top }; if (horizontallyCentered) { ctf.HorizontalAlignment = CanvasHorizontalAlignment.Center; } if (verticallyCentered) { ctf.VerticalAlignment = CanvasVerticalAlignment.Center;; } if (!leftAligned && !horizontallyCentered) { ctf.HorizontalAlignment = CanvasHorizontalAlignment.Right; } canvasArgs.DrawingSession.DrawText(text, new Vector2((float)x, (float)y), textColor, ctf); }
//отрисовка тестового набора private void canvas_Draw( Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { for (int x = 0; x < DIMENSION; x++) { for (int y = 0; y < DIMENSION; y++) { args.DrawingSession.DrawRectangle(x * width, y * width, width, width, Color.FromArgb(254, (byte)(Convert.ToInt32(TrainingSet[x * DIMENSION + y][0] * 254)), (byte)(Convert.ToInt32(TrainingSet[x * DIMENSION + y][1] * 254)), (byte)(Convert.ToInt32(TrainingSet[x * DIMENSION + y][2] * 254)) ), width); } } }
private Tuple <Rect, Rect> GetSourceDest(SoftwareBitmap background, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { double sourceWidth; double sourceHeight; double destWidth; double destHeight; if (background == null) { return(null); } var c = CanvasBitmap.CreateFromSoftwareBitmap(args.DrawingSession, background); sourceWidth = background.PixelWidth; sourceHeight = background.PixelHeight; var sourceAspectRatio = sourceWidth / sourceHeight; Rect sourceRect; destWidth = canvLeft.ActualWidth; destHeight = canvLeft.ActualHeight; var destAspectRatio = destWidth / destHeight; var destRect = new Rect() { X = 0, Y = 0, Width = destWidth, Height = destHeight }; if (sourceAspectRatio > destAspectRatio) { var sourceNewWidth = sourceHeight * destAspectRatio; sourceRect = new Rect() { X = (sourceWidth - sourceNewWidth) / 2, Y = 0, Width = sourceNewWidth, Height = sourceHeight }; } else { var sourceNewHeight = sourceWidth * destAspectRatio; sourceRect = new Rect() { X = 0, Y = (sourceHeight - sourceNewHeight) / 2, Width = sourceWidth, Height = sourceNewHeight }; } return(new Tuple <Rect, Rect>(sourceRect, destRect)); }
private void Canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { float centerX = _centerVector.X; float centerY = _centerVector.Y; float radiusMax = _radiusMax; float radiusMin = _radiusMin; // 创建路径变量 int colorCount = _wheelColors.Count; // 颜色数量 Double angel = 360.0 / colorCount; // 计算夹角(注:计算参数必须为浮点数,否则结果为0) Double rotate = 0; // 起始角度 float pointX, pointY; // 缓存绘图路径点 _wheelColors.ForEach((color) => { color.A = Argb_A; pointX = centerX + radiusMin * (float)Math.Cos(rotate * Math.PI / 180); pointY = centerY + radiusMin * (float)Math.Sin(rotate * Math.PI / 180); Vector2 point1 = new Vector2(pointX, pointY); rotate += angel; pointX = centerX + radiusMax * (float)Math.Cos(rotate * Math.PI / 180); pointY = centerY + radiusMax * (float)Math.Sin(rotate * Math.PI / 180); Vector2 point3 = new Vector2(pointX, pointY); double d = Math.Atan2((_getColorPointer.Y - _centerVector.Y), (_getColorPointer.X - _centerVector.X)) * 180 / Math.PI; d = Math.Round(d); double r = Math.Round(rotate); if (d < 0) { d = d + 360; } if (d == r) { centercolors = color; } CanvasPathBuilder path = new CanvasPathBuilder(sender); path.BeginFigure(point1); path.AddLine(point3); path.EndFigure(CanvasFigureLoop.Open); CanvasGeometry apple = CanvasGeometry.CreatePath(path); args.DrawingSession.DrawGeometry(apple, color); }); centercolors.A = Argb_A; args.DrawingSession.FillCircle(_centerVector, _radiusCenter, centercolors); args.DrawingSession.DrawCircle(_getColorPointer, _radiusGetColor, Colors.Wheat); sliderColor.Color = Color.FromArgb(centercolors.A, centercolors.R, centercolors.G, centercolors.B); }
/* * Win2DのCanvasControlの描画 */ private void Win2DCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { Debug.WriteLine("<<--- Draw"); DrawList.Clear(); if (double.IsNaN(LineHeight)) { // 最初の場合 // 1行の高さを計算します。 Rect M_rc = new CanvasTextLayout(args.DrawingSession, "M", TextFormat, float.MaxValue, float.MaxValue).LayoutBounds; LineHeight = M_rc.Height; // 空白の幅を計算します。 Rect sp_M_rc = new CanvasTextLayout(args.DrawingSession, " M", TextFormat, float.MaxValue, float.MaxValue).LayoutBounds; SpaceWidth = sp_M_rc.Width - M_rc.Width; } // ビューの幅と高さ float view_w = (float)Win2DCanvas.ActualWidth; float view_h = (float)Win2DCanvas.ActualHeight; // ビュー内に表示する行数 ViewLineCount = (int)(view_h / LineHeight); // フォーカスの有無によって枠の色を変えます。 if (OverlappedButton.FocusState == FocusState.Unfocused) { // フォーカスがない場合 args.DrawingSession.DrawRectangle(0, 0, view_w, view_h, Colors.Gray, 1); } else { // フォーカスがある場合 args.DrawingSession.DrawRectangle(0, 0, view_w, view_h, Colors.Blue, 1); } // ビュー内の先頭行のインデックス int start_line_idx = (int)(EditScroll.VerticalOffset / LineHeight); // 現在行 int line_idx = 0; // 文字の現在位置 int pos; for (pos = 0; pos < Chars.Count && line_idx < start_line_idx; pos++) { if (Chars[pos].Chr == LF) { line_idx++; if (line_idx == start_line_idx) { pos++; break; } } } float x_start = (float)ViewPadding.X; float y = (float)ViewPadding.Y; int sel_start = SelStart; int sel_end = SelEnd; for (; ; pos++) { StringWriter line_sw = new StringWriter(); float x = x_start; int start_pos = pos; for (; pos < Chars.Count;) { StringWriter sw = new StringWriter(); UnderlineType under_line = Chars[pos].Underline; bool selected = (sel_start <= pos && pos < sel_end); int phrase_start_pos = pos; for (; pos < Chars.Count && Chars[pos].Chr != LF && Chars[pos].Underline == under_line && (sel_start <= pos && pos < sel_end) == selected; pos++) { sw.Write(Chars[pos].Chr); } //String str = new string((from c in Chars select c.Chr).ToArray()); String str = sw.ToString(); line_sw.Write(str); Size sz = MeasureText(str, TextFormat); float xe = (float)(x + sz.Width); float yb = (float)(y + sz.Height); if (selected) { args.DrawingSession.FillRectangle(x, y, (float)sz.Width, (float)sz.Height, Colors.Blue); args.DrawingSession.DrawText(str, x, y, Colors.White, TextFormat); } else { args.DrawingSession.DrawText(str, x, y, Colors.Black, TextFormat); switch (under_line) { case UnderlineType.None: case UnderlineType.Undefined: break; case UnderlineType.Wave: args.DrawingSession.DrawLine(x, yb, xe, yb, Colors.Blue, 1); break; case UnderlineType.Thick: args.DrawingSession.DrawLine(x, yb, xe, yb, Colors.Black, 1); break; case UnderlineType.Thin: args.DrawingSession.DrawLine(x, yb, xe, yb, Colors.Green, 1); break; default: Debug.WriteLine("unknown under-line {0}", under_line); break; } } DrawList.Add(new TShape(x, y, sz, phrase_start_pos, pos + 1)); x += (float)sz.Width; if (Chars.Count <= pos || Chars[pos].Chr == LF) { break; } } String line_str = line_sw.ToString(); // 挿入カーソルの位置を得ます。 int cursor_pos; if (DropPos != -1) { // ドロップ先がある場合 // ドロップ先に挿入カーソルを描画します。 cursor_pos = DropPos; } else { // ドロップ先がない場合 // 現在の選択位置に挿入カーソルを描画します。 cursor_pos = SelCurrent; } if (OverlappedButton.FocusState != FocusState.Unfocused && start_pos <= cursor_pos && cursor_pos <= pos) { Size current_sz = MeasureText(line_str.Substring(0, cursor_pos - start_pos), TextFormat); float x1 = (float)(x_start + current_sz.Width); float y0 = y; float y1 = (float)(y + current_sz.Height); args.DrawingSession.DrawLine(x1, y0, x1, y1, Colors.Blue, 1); } line_idx++; if (ViewLineCount <= line_idx - start_line_idx) { break; } // 現在の行の高さを計算して、yに加算します。 y += (float)MeasureText(line_str, TextFormat).Height; if (Chars.Count <= pos) { // 文書の最後の場合 break; } } }
private void OnDebugDraw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { var session = args.DrawingSession; session.Clear(Colors.DarkSlateBlue); var dpi = Windows.Graphics.Display.DisplayProperties.LogicalDpi; var layers = Sequensor.Controller.CachedFrame; foreach (var layer in layers) { var l = layer; foreach (var render in layer) { var cbi = CanvasBitmap.CreateFromSoftwareBitmap(session.Device, render.Source); ICanvasImage image = new Transform2DEffect { Source = cbi, TransformMatrix = render.Transformaion }; session.DrawImage(image); } } }
private void Canvas_OnDraw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { var draw = args.DrawingSession; var s = ViewModel.Solid; //var c = 0; //var r = 0; //var w = ViewModel.Width; for (var i = 0; i < s.Length; i++) { var temp = s[i]; draw.FillRectangle(Rectangle[i], temp.WeizCsefsimile ? FillSolidColor.Color : Colors.Transparent); draw.DrawRectangle(Rectangle[i], temp.WeizCsefsimile ? BoundColor : Colors.Transparent); //c++; //if (c == ViewModel.Col) //{ // c = 0; // r++; //} } //draw.DrawText("lindexi", Ran.Next(10, 100), Ran.Next(10, 100), 500, 50, r(), new CanvasTextFormat() //{ // FontSize = 100 //}); //for (int i = 0; i < 10; i++) //{ // draw.DrawLine(Ran.Next(10, 100), Ran.Next(10, 100), Ran.Next(100, 1000), Ran.Next(100, 1000), r()); //} //if (img != null) //{ // draw.DrawImage(img, Ran.Next(10, 1000), rc()); //} //else //{ // Img().Wait(); //} //Color r() //{ // return Color.FromArgb(0xFF, rc(), rc(), rc()); //} //byte rc() //{ // return (byte)(Ran.NextDouble() * 255); //} //async Task Img() //{ // img = await CanvasBitmap.LoadAsync(canvas, new Uri("ms-appx:///Assets/SplashScreen.png")); //} }
private void Canvas_DrawRight(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { renderGameStateRight.Update(game.gameState, args); }
private void CanvasControl_Draw(Win2DCanvas.UI.Xaml.CanvasControl sender, Win2DCanvas.UI.Xaml.CanvasDrawEventArgs args) { _win2dBitmap.SetPixelColors(_bitmapColors); args.DrawingSession.DrawImage(_win2dBitmap, 0, 0); }
private void ImageCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { var ds = args.DrawingSession; if (_canvasImage == null) { ds.Clear(Colors.White); return; } var imageBounds = _canvasImage.GetBounds(sender); var min = Math.Min(imageBounds.Height, imageBounds.Width); imageBounds.X = (imageBounds.Width - min) / 2; imageBounds.Y = (imageBounds.Height - min) / 2; imageBounds.Height = min; imageBounds.Width = min; ds.Clear(Colors.White); ds.DrawImageWithEffect(_canvasImage, new Rect(0, 0, 950, 950), imageBounds, _selectedEffectType); }
/// <summary> /// 画布绘制 /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void MyCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { var target = GetDrawings(true); // if (target != null) { args.DrawingSession.DrawImage(target); } }
private void Canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { args.DrawingSession.DrawText("Hello, World!", 100, 100, Colors.Black); }
private void Canvas1_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { CanvasDrawingSession ds = args.DrawingSession; if (gameOver) { ds.DrawText("Game Over, You Win!!!", (float)Canvas1.ActualWidth / 2, (float)Canvas1.ActualHeight / 2, Colors.Green); ds.DrawText("Restarting in " + restartCountdown / 60 + "s.", (float)Canvas1.ActualWidth / 2, (float)(Canvas1.ActualHeight / 2) + 50, Colors.Lime); if (restartCountdown <= 0) { //Starting positions mainCharacter.x = 40; mainCharacter.y = Canvas1.ActualHeight - 115; mainCharacter.box = new Rect(mainCharacter.x, mainCharacter.y, 40, 40); gameOver = false; restartCountdown = 600; } else { restartCountdown--; } Canvas1.Invalidate(); return; } if (mainCharacter == null) { mainCharacter = new GameCharacter(Canvas1); } if (mainCharacter.y > Canvas1.ActualHeight) { mainCharacter.y = 0; } if (mainCharacter.x > Canvas1.ActualWidth) { mainCharacter.x = 0; } else if (mainCharacter.x < 0) { mainCharacter.x = Canvas1.ActualWidth - mainCharacter.box.Width; } //true when the box intersects with a single box. mainCharacter.onGround = !shapes.Keys.ToList().TrueForAll(rect => !checkIntersect(mainCharacter.box, rect)); //Handle character horizontal acceleration if (Window.Current.CoreWindow.GetKeyState(VirtualKey.D).HasFlag(CoreVirtualKeyStates.Down)) { if (mainCharacter.hSpeed < 10) { mainCharacter.hSpeed++; } } else if (Window.Current.CoreWindow.GetKeyState(VirtualKey.A).HasFlag(CoreVirtualKeyStates.Down)) { if (mainCharacter.hSpeed > -10) { mainCharacter.hSpeed--; } } else { if (mainCharacter.hSpeed > 0) { mainCharacter.hSpeed--; } else if (mainCharacter.hSpeed < 0) { mainCharacter.hSpeed++; } } if (!mainCharacter.onGround) { mainCharacter.box.Y -= mainCharacter.vSpeed; foreach (Rect rect in shapes.Keys) { if (checkIntersect(mainCharacter.box, rect)) { mainCharacter.y = rect.Y - mainCharacter.box.Height; mainCharacter.onGround = true; } } if (!mainCharacter.onGround) { mainCharacter.y -= mainCharacter.vSpeed; mainCharacter.vSpeed--; } else { mainCharacter.vSpeed = -2; } } else { mainCharacter.box.Y -= mainCharacter.vSpeed; foreach (Rect rect in shapes.Keys) { if (checkIntersect(mainCharacter.box, rect) && mainCharacter.y - mainCharacter.box.Height > rect.Y) { mainCharacter.y = rect.Y - mainCharacter.box.Height; } } } //Character Movement adjustments mainCharacter.x += mainCharacter.hSpeed; //Draw Rectangles foreach (KeyValuePair <Rect, Color> item in shapes) { ds.FillRectangle(item.Key, item.Value); } mainCharacter.draw(ds); //Check win condition if (mainCharacter.y < 300 && mainCharacter.x > 1000 && mainCharacter.x < 1140) { gameOver = true; } Canvas1.Invalidate(); }
private void Win2DCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { if (_DrawingCanvas != null) { args.DrawingSession.DrawImage(_DrawingCanvas, new Rect(new Point(0, 0), _DrawingCanvas.Size), new Rect(new Point(0, 0), _DrawingCanvas.Size)); } }
private void Canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { // Start drawing session and clear background to white. var session = args.DrawingSession; args.DrawingSession.Clear(Colors.White); // Set the center of the radial gradient as the center of the image. radialBrush.Center = new System.Numerics.Vector2((float)(image.Size.Width / 2.0f), (float)(image.Size.Height / 2.0f)); // Assing gradient radius from slider control. radialBrush.RadiusX = radialBrush.RadiusY = (float)BlurRadius.Value; // Draw unaltered image first. session.DrawImage(image, image.Bounds); // Create a layer, this way all elements drawn will be affected by a transparent mask // which in our case is the radial gradient. using (session.CreateLayer(radialBrush)) { // Create gaussian blur effect. using (var blurEffect = new GaussianBlurEffect()) { // Set image to blur. blurEffect.Source = image; // Set blur amount from slider control. blurEffect.BlurAmount = (float)BlurAmount.Value; // Explicitly set optimization mode to highest quality, since we are using big blur amount values. blurEffect.Optimization = EffectOptimization.Quality; // This prevents the blur effect from wrapping around. blurEffect.BorderMode = EffectBorderMode.Hard; // Draw blurred image on top of the unaltered one. It will be masked by the radial gradient // thus showing a transparent hole in the middle, and properly overlaying the alpha values. session.DrawImage(blurEffect, 0, 0); } } }
private void DrawerCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { foreach (PageLayer item in LayerItems) { item.Draw(args.DrawingSession); } }
private void Canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { args.DrawingSession.DrawText("Hello, World!", 100, 100, Colors.Black); //Color[] colors = { ColorHelper.FromArgb(0, 0, 0, 0) }; //CanvasBitmap.CreateFromColors(sender, colors, 10, 20); }
private void Canvas1_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { CanvasDrawingSession ds = args.DrawingSession; if (!ListBoxItem1.IsSelected) { //Drawing 1 //Sun ds.FillEllipse(0, 0, 150, 100, Colors.Yellow); //Grass ds.FillRectangle(new Rect(0, 700, 5000, 200), Colors.Green); //Tree ds.FillRectangle(new Rect(200, 325, 80, 400), Colors.SaddleBrown); ds.FillEllipse(240, 325, 100, 100, Colors.Green); ds.FillEllipse(200, 350, 100, 100, Colors.Green); ds.FillEllipse(260, 350, 100, 100, Colors.Green); //House ds.FillRectangle(new Rect(800, 475, 350, 300), Colors.DarkRed); ds.DrawLine(new Vector2(800, 475), new Vector2(1150, 775), Colors.White, 10); ds.DrawLine(new Vector2(800, 775), new Vector2(1150, 475), Colors.White, 10); Vector2[] roof = { new Vector2(800, 475), new Vector2(975, 375), new Vector2(1150, 475) }; CanvasPathBuilder pathBuilder = new CanvasPathBuilder(Canvas1); pathBuilder.AddGeometry(CanvasGeometry.CreatePolygon(Canvas1, roof)); ds.FillGeometry(CanvasGeometry.CreatePath(pathBuilder), Colors.SaddleBrown); } else { Color[] rainbow = { Colors.Red, Colors.Orange, Colors.Yellow, Colors.Green, Colors.Blue, Colors.Indigo, Colors.Violet }; //Drawing 2 Vector2 startingPoint = new Vector2((float)(ActualWidth / 2), (float)(ActualHeight / 2)); int angleIncrement = 3; int sideLength = 60; int angle = 0; hexagonsDrawn++; if (hexagonsDrawn == 1000) { //Draw hexagons for (int i = 0; i < hexagonsDrawn; i++) { for (int j = 0; j < 6; j++) { startingPoint = DrawLine(ds, startingPoint, angle, sideLength, rainbow[i % rainbow.Length]); angle += 60; } angle += angleIncrement; sideLength++; } hexagonsDrawn = 0; } else { //Draw hexagons for (int i = 0; i < hexagonsDrawn; i++) { for (int j = 0; j < 6; j++) { startingPoint = DrawLine(ds, startingPoint, angle, sideLength, rainbow[i % rainbow.Length]); angle += 60; } angle += angleIncrement; sideLength++; } Task.Delay(10).Wait(); Canvas1.Invalidate(); } } }
private void canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { for (int i = 0; i < DataPointsPerFrame; i++) { var delta = _rand.NextDouble() * .1 - .05; _lastValue = Math.Max(0d, Math.Min(1d, _lastValue + delta)); _data.Add(_lastValue); } if (Data.IsChecked == true) { _chartRenderer.RenderData(canvas, args, Colors.Black, DataStrokeThickness, _data, renderArea: ChartShow.IsChecked == true); } canvas.Invalidate(); //_chartRenderer.RenderAveragesAsPieChart(canvas, args, pieValues, new List<Color>(new[] { Colors.DarkSalmon, Colors.Azure, Colors.LemonChiffon, Colors.Honeydew, Colors.Pink })); }
private void BackgroundCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { //var startAngle = DegreesToRadians(-15); //var sweepAngle = DegreesToRadians(30); //var progress = (float)Slide.Value / 100f; //var size = 1 + 4 * progress; //for (int i = 0; i < 4; i++) //{ // using (var builder = new CanvasPathBuilder(sender)) // { // var centerPoint = new Vector2((1 + 4 * progress), 6); // var startPoint = centerPoint + Vector2.Transform(Vector2.UnitX, Matrix3x2.CreateRotation(startAngle)) * size; // builder.BeginFigure(startPoint); // builder.AddArc(centerPoint, size, size, startAngle, sweepAngle); // builder.EndFigure(CanvasFigureLoop.Open); // using (var geometry = CanvasGeometry.CreatePath(builder)) // { // var alpha = (i == 0) ? progress : (i == 4 - 1) ? (1.0f - progress) : 1.0f; // args.DrawingSession.DrawGeometry(geometry, Color.FromArgb((byte)(alpha * 255), 0xFF, 0x00, 0x0), 2, new CanvasStrokeStyle { StartCap = CanvasCapStyle.Round, EndCap = CanvasCapStyle.Round }); // } // size += 4; // } //} }
private void canvasControl_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { int stroke = 3; float width = (float)this.ActualWidth; float height = (float)this.ActualHeight; float radius = Math.Min(width, height) / 2 - 2 * stroke; float centerX = width / 2; float centerY = height / 2; float lineEndX = radius * (float)Math.Cos(Math.PI * Angle / 180) + centerX; float lineEndY = radius * (float)Math.Sin(Math.PI * Angle / 180) + centerY; args.DrawingSession.DrawCircle(centerX, centerY, radius, Colors.Red, stroke); args.DrawingSession.DrawLine(centerX, centerY, lineEndX, lineEndY, Colors.Green, stroke); args.DrawingSession.DrawText(Angle.ToString(), centerX, centerY, Colors.Black); }
private void Canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { ProcessPendingInk(); DrawStrokesToInkSurface(args.DrawingSession, _sessionStrokes); DrawStrokesToInkSurface(args.DrawingSession, _allStrokes); }
private void LcdScreen_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { }
private void CanvasControlRight_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { Rect destRect; lock (lockObj) { CanvasBitmap c; if (background == null) { return; } c = CanvasBitmap.CreateFromSoftwareBitmap(args.DrawingSession, background); var rects = GetSourceDest(background, args); args.DrawingSession.DrawImage(c, rects.Item2, rects.Item1); destRect = rects.Item2; } if (figure == null) { return; } DrawFigure(args, destRect, zIndex, rightEyePos); }
private void BGCycle_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { CanvasGradientStop[] gradientStop = new CanvasGradientStop[2]; gradientStop[0] = new CanvasGradientStop(); gradientStop[0].Color = Color.FromArgb(180, 18, 208, 255); gradientStop[0].Position = 0f; gradientStop[1] = new CanvasGradientStop(); gradientStop[1].Color = Color.FromArgb(0, 255, 255, 255); gradientStop[1].Position = 1f; CanvasRadialGradientBrush brush = new CanvasRadialGradientBrush(sender, gradientStop); brush.RadiusX = 200; brush.RadiusY = 200; brush.Center = new Vector2(200, 200); args.DrawingSession.FillCircle(200, 200, 200, brush); }
private void joinCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { var canvas_target = GetDrawing(true); if (canvas_target != null) { args.DrawingSession.DrawImage(canvas_target); } }
private void gauge_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { using (CanvasDrawingSession drawingSession = args.DrawingSession) { Vector2 outputSize = new Vector2((float)(ActualWidth), (float)(ActualHeight)); Vector2 sourceSize = new Vector2((float)100.0f, (float)-100.0f); drawingSession.Transform = GetDisplayTransform(outputSize, sourceSize); using (var geometry = CanvasGeometry.CreatePath(CreateBackgroundGauge(sender))) { drawingSession.FillGeometry(geometry, Color.FromArgb(255, 25, 25, 25)); // Colors.DarkSlateGray); } using (var geometry2 = CanvasGeometry.CreatePath(CreateForegroundGauge(sender))) { drawingSession.FillGeometry(geometry2, ForegroundColor); } using (var geometry3 = CanvasGeometry.CreatePath(CreateBorderGauge(sender))) { drawingSession.DrawGeometry(geometry3, Colors.White, 2.0f); } outputSize = new Vector2((float)(ActualWidth), (float)(ActualHeight)); sourceSize = new Vector2((float)100.0f, (float)100.0f); drawingSession.Transform = GetDisplayTransform(outputSize, sourceSize); string text = string.Format("{0:0} L", DeliveredLitres); FontWeight weight = new FontWeight(); weight.Weight = 500; using (CanvasTextFormat textFormat = new CanvasTextFormat { FontSize = 10.0f, FontWeight = weight, WordWrapping = CanvasWordWrapping.NoWrap }) using (CanvasTextLayout layout = new CanvasTextLayout(drawingSession, text, textFormat, 0.0f, 0.0f)) { float xLocation = -(float)layout.DrawBounds.Width / 2; float yLocation = -(float)layout.DrawBounds.Height - 10; outputSize = new Vector2((float)(ActualWidth), (float)(ActualHeight)); sourceSize = new Vector2(100.0f, 100.0f); drawingSession.Transform = GetDisplayTransform(outputSize, sourceSize); drawingSession.DrawTextLayout(layout, xLocation, yLocation, ForegroundColor); } text = string.Format("{0:0} L", PresetLitres); weight = new FontWeight(); weight.Weight = 500; using (CanvasTextFormat textFormat = new CanvasTextFormat { FontSize = 15.0f, FontWeight = weight, WordWrapping = CanvasWordWrapping.NoWrap }) using (CanvasTextLayout layout = new CanvasTextLayout(drawingSession, text, textFormat, 0.0f, 0.0f)) { float xLocation = -(float)layout.DrawBounds.Width / 2; float yLocation = -(float)layout.DrawBounds.Height + 10; drawingSession.DrawTextLayout(layout, xLocation, yLocation, ForegroundColor); } } }