如何绘制与配置2D图形界面

Posted hushzhang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何绘制与配置2D图形界面相关的知识,希望对你有一定的参考价值。

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="521.082" Width="525">
    <Grid Name="grid">
        <Line Name="line" X1="10" Y1="10" X2="100" Y2="100" Stroke="Black" VerticalAlignment="Center"></Line>
        <Ellipse Name="ellipse" Fill="Red" HorizontalAlignment="Left" Height="112" Margin="187,66,0,0" Stroke="Black" VerticalAlignment="Top" Width="167"/>
        <Button Content="Button" HorizontalAlignment="Left" Margin="53,73,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
        <Canvas HorizontalAlignment="Left" Height="156" Margin="189,313,0,0" VerticalAlignment="Top" Width="158">
            <Ellipse Height="100" Canvas.Left="31" Stroke="Black" Canvas.Top="29" Width="100"/>
        </Canvas>
        <Path Stroke="Red" StrokeThickness="5" Data="M30,30 Q 60,30 30,90"></Path>
        <Polygon Stroke="Blue" StrokeThickness="4" Points="40,100 80,120 60,160">
            <Polygon.Fill>
                <SolidColorBrush Color="Yellow"></SolidColorBrush>
            </Polygon.Fill>
        </Polygon>
        <Canvas Width="100" Height="100">
            <Ellipse Fill="Yellow" Stroke="Black"
                    StrokeThickness="7"
                    Width="100" Height="100"></Ellipse>
            <Ellipse Fill="Black" Width="10" Height="15"
                     Canvas.Left="28" Canvas.Top="28"></Ellipse>
            <Ellipse Fill="Black" x:Name="myEllipse"
                     Width="10" Height="15"
                     Canvas.Left="62" Canvas.Top="28"></Ellipse>
            <Path Stroke="Black" StrokeThickness="6" Data="M30,60 Q 50,90 70,60"></Path>
        </Canvas>
    </Grid>
</Window>

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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;

namespace WpfApplication1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Line l1 = new Line();
            l1.X1 = 100;
            l1.Y1 = 100;
            l1.X2 = 500;
            l1.Y2 = 100;
            l1.Stroke = new SolidColorBrush(Color.FromRgb(0,0,225));
            l1.StrokeThickness = 2;
            grid.Children.Add(l1);

            ellipse.Height = 218;
            
        }

    }
}

 

技术分享

以上是关于如何绘制与配置2D图形界面的主要内容,如果未能解决你的问题,请参考以下文章

shader编程-2D基本图形SDF(有向距离场)介绍与使用(WebGL-Shader开发基础05)

绘图与滤镜全面解析--Quartz 2D Core Image

《Java游戏编程原理与实践教程》读书笔记(第3章——Java图形处理和Java 2D)

如何使用vscode远程debug linux图形界面程序

Win 10 应用开发UI Composition 札记:绘制图形

Android面试收集录 2D绘图与动画技术