0

WPF を使用して何かを描画しようとしていますが、うまくいきません。私は WinForm Graphics の描画メソッドを探しています。私は次のようにTetrahedronしていPoint[]ますDraw。形に描きたい。私はそのようにやっています:

using System;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Cg1Model;

namespace Cg1Wpf
{
    internal class Tetrahedron
    {
        public readonly ShapePoint[] Points;

        public Tetrahedron(ShapePoint[] points)
        {
            if (points.Length != 4)
                throw new ArgumentException(@"Invalid points count", "points");
            Points = points;
        }

        public ImageSource Draw()
        {
            var points = Points.Select(IsometricConvertion).ToArray();

            int pixelWidth = (int) (points.Max(p => p.X) - points.Min(p => p.X));
            int pixelHeight = (int) (points.Max(p => p.Y) - points.Min(p => p.Y));

            var bmp = new RenderTargetBitmap(pixelWidth, pixelHeight, 120, 96, PixelFormats.Pbgra32);
            for (int i = 0; i < points.Length - 1; i++)
            {
                var line = new Line
                           {
                               X1 = points[i].X,
                               Y1 = points[i].Y,
                               X2 = points[i + 1].X,
                               Y2 = points[i + 1].Y,
                               SnapsToDevicePixels = true,
                               Stroke = Brushes.Black,
                               StrokeThickness = 5,
                               Fill = Brushes.Blue
                           };
                bmp.Render(line);
            }
            return bmp;
        }

        private Point IsometricConvertion(ShapePoint point)
        {
            //TODO: change to normal isometric
            var result = new Point();

            result.X = point.X;
            result.Y = point.Y;
            return result;
        }
    }
}

シェイプポイントの場所

public struct ShapePoint
{
    public int X { get; set; }
    public int Y { get; set; }
    public int Z { get; set; }


    public ShapePoint(int y, int x, int z) : this()
    {
        Y = y;
        X = x;
        Z = z;
    }
}

しかし、私がそれを呼んでいるとき

private void Button_Click(object sender, RoutedEventArgs e)
{
    ShapePoint[] points =
    {
        new ShapePoint(10,20,30), 
        new ShapePoint(50,30,20),
        new ShapePoint(70,90,190),
        new ShapePoint(20,54,0)
    };
    var tetra = new Tetrahedron(points);
    Img.Source = tetra.Draw();
}

それは何も描きません。私は何の間違いをしているのですか?

4

1 に答える 1