2014-12-18 1 views
1

작은 프로젝트에서 작동 가능한 C# 코드를 제거했지만 문제가 발생했습니다. 이 코드는 재생중인 비디오 위에 선을 그 으려하지만 두 번째 선이 원래 선의 끝에 그리기 시작하여 연결된 선으로 경로를 표시 할 수 있도록 수정해야합니다.C#에서 연결된 선 그리기

재생의 2 초에서 시작하는 첫 번째 줄 끝에서 두 번째 줄을 어떻게 그릴 수 있습니까? 그냥 지점의 목록을 작성하고이 메소드를 호출

public MainWindow() 
    { 
     InitializeComponent(); 
     Line line = new Line(); 
     canvas1.Children.Add(line); 
     line.Stroke = Brushes.Red; 
     line.StrokeThickness = 2; 
     line.X1 = 100; 
     line.Y1 = 100; 
     Storyboard sb = new Storyboard(); 
     DoubleAnimation da = new DoubleAnimation(line.Y2, 500, new Duration(new TimeSpan(0, 0, 1))); 
     DoubleAnimation da1 = new DoubleAnimation(line.X2, 150, new Duration(new TimeSpan(0, 0, 1))); 
     Storyboard.SetTargetProperty(da, new PropertyPath("(Line.Y2)")); 
     Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X2)")); 
     sb.Children.Add(da); 
     sb.Children.Add(da1); 
     line.BeginStoryboard(sb); 
+0

Visibility 속성을 대상으로하는 두 번째 줄에서 ObjectAnimationUsingKeyFrames를 사용하십시오. 키 프레임 0에서 축소 된 것으로 설정하고 키 프레임 00:02:00에서 표시로 설정합니다. 두 번째 해결책은 DoubleAnimationUsingKeyFrames를 사용하여 Opacity 속성을 설정하는 것입니다. – nkoniishvt

+0

2 초에 새 라인을 간단히 만들 수있는 방법이 없습니까? – caine1337

+0

존재하는 경우이 방법을 모른다. 스토리 보드는 속성을 애니메이션으로 만들지 만 아무것도 만들지 않습니다. 그래서 나는 당신이 할 수 없다고 생각합니다. – nkoniishvt

답변

0

이 내가 생각 해낸 것입니다. 그것은 점에서 점으로 선을 그릴 것입니다.

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Navigation; 
using System.Windows.Shapes; 
using System.Windows.Media.Animation; 

namespace WpfApplication4 
{ 
    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
     List<Point> points = null; 
     List<Line> lines = null; 
     List<Storyboard> boards = null; 

     public MainWindow() 
     { 
      InitializeComponent(); 

      points = new List<Point>(); 
      lines = new List<Line>(); 
      boards = new List<Storyboard>(); 

      points.Add(new Point(0, 0)); 
      points.Add(new Point(200, 200)); 
      points.Add(new Point(200, 0)); 
      points.Add(new Point(0, 0)); 
      points.Add(new Point(0, 200)); 
      points.Add(new Point(200, 200)); 
      points.Add(new Point(300, 200)); 

      SetupLines(); 
      DrawLines(); 
     } 

     public void SetupLines() 
     { 
      int speed = 1; 
      lines.Add(new Line()); 
      boards.Add(new Storyboard()); 

      for (int i = 0; i < points.Count - 1; i++) 
      { 
       lines.Add(new Line()); 
       boards.Add(new Storyboard()); 

       canvas1.Children.Add(lines[i]); 
       lines[i].Stroke = Brushes.Red; 
       lines[i].StrokeThickness = 7; 

       lines[i].X1 = points[i].X; 
       lines[i].Y1 = points[i].Y; 
       lines[i].X2 = points[i].X; 
       lines[i].Y2 = points[i].Y; 

       DoubleAnimation da = new DoubleAnimation(points[i].X, points[i+1].X, new Duration(new TimeSpan(0, 0, speed))); 
       DoubleAnimation da1 = new DoubleAnimation(points[i].Y, points[i+1].Y, new Duration(new TimeSpan(0, 0, speed))); 

       Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)")); 
       Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.Y2)")); 

       boards[i].Children.Add(da); 
       boards[i].Children.Add(da1); 

       da.BeginTime = new TimeSpan(0, 0, i * speed); 
       da1.BeginTime = new TimeSpan(0, 0, i * speed); 

       lines.Add(new Line()); 
       boards.Add(new Storyboard()); 
      } 
     } 

     public void DrawLines() 
     { 
      for (int i = 0; i < boards.Count - 1; i++) 
      { 
       lines[i].BeginStoryboard(boards[i]); 
      } 
     } 
    } 
}