C# 如何将带有填充的椭圆转换为C语言中的ImageDrawing#
我已经创建了一个椭圆。然后如何将该椭圆转换为ImageDrawing 基本上我要做的是拍摄3张图片,(上画中间画和下画) 将它们堆叠在一起以创建单个图形。但我也告诉用户,当其他图层(即底部和顶部)保持静止时,可以旋转中间的图形 我必须在代码中完成这项工作,而不是XAML,因为实体是数据库驱动的 我使用DrawingGroup来堆叠这3幅图像。C# 如何将带有填充的椭圆转换为C语言中的ImageDrawing#,c#,wpf,system.windows.media,C#,Wpf,System.windows.media,我已经创建了一个椭圆。然后如何将该椭圆转换为ImageDrawing 基本上我要做的是拍摄3张图片,(上画中间画和下画) 将它们堆叠在一起以创建单个图形。但我也告诉用户,当其他图层(即底部和顶部)保持静止时,可以旋转中间的图形 我必须在代码中完成这项工作,而不是XAML,因为实体是数据库驱动的 我使用DrawingGroup来堆叠这3幅图像。 问题是我无法将中间的图形旋转到23 我希望我能解释清楚。有人建议我尝试使用椭圆,但我需要将它们转换为ImageDrawing 任何帮助都很好。为什么不能
问题是我无法将中间的图形旋转到23 我希望我能解释清楚。有人建议我尝试使用椭圆,但我需要将它们转换为ImageDrawing
任何帮助都很好。为什么不能使用XAML?这是我制作的一个量具,它非常具有可伸缩性,可以绑定到您想要的任何数据 XAML:
代码隐藏:
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 clock
{
/// <summary>
/// Interaction logic for ctlClock.xaml
/// </summary>
public partial class ctlGauge : UserControl
{
public static DependencyProperty MaxValueProperty = DependencyProperty.Register("MaxValue", typeof(double), typeof(ctlGauge), new FrameworkPropertyMetadata(new PropertyChangedCallback(MaxValue_Changed)));
public double MaxValue
{
get { return (double)GetValue(MaxValueProperty); }
set { SetValue(MaxValueProperty, value); }
}
private static void MaxValue_Changed(DependencyObject o, DependencyPropertyChangedEventArgs args)
{
ctlGauge thisClass = (ctlGauge)o;
thisClass.SetMaxValue();
}
private void SetMaxValue()
{
MaxPointAngle = GetValueAngle(MaxValue);
}
public static DependencyProperty CurrentValueProperty = DependencyProperty.Register("CurrentValue", typeof(double), typeof(ctlGauge), new FrameworkPropertyMetadata(new PropertyChangedCallback(CurrentValue_Changed)));
public double CurrentValue
{
get { return (double)GetValue(CurrentValueProperty); }
set { SetValue(CurrentValueProperty, value); }
}
private static void CurrentValue_Changed(DependencyObject o, DependencyPropertyChangedEventArgs args)
{
ctlGauge thisClass = (ctlGauge)o;
thisClass.SetCurrentValue();
}
private void SetCurrentValue()
{
MainPointerAngle = GetValueAngle(CurrentValue);
}
public static DependencyProperty MainPointerAngleProperty = DependencyProperty.Register("MainPointerAngle", typeof(double), typeof(ctlGauge), new FrameworkPropertyMetadata(new PropertyChangedCallback(MainPointerAngle_Changed)));
public static DependencyProperty MaxPointAngleProperty = DependencyProperty.Register("MaxPointAngle", typeof(double), typeof(ctlGauge), new FrameworkPropertyMetadata(new PropertyChangedCallback(MaxPointAngle_Changed)));
public double MaxPointAngle
{
get { return (double)GetValue(MaxPointAngleProperty); }
set { SetValue(MaxPointAngleProperty, value); }
}
private static void MaxPointAngle_Changed(DependencyObject o, DependencyPropertyChangedEventArgs args)
{
ctlGauge thisClass = (ctlGauge)o;
thisClass.SetMaxPointAngle();
}
private void SetMaxPointAngle()
{
//Put Instance MaxPointAngle Property Changed code here
}
public double MainPointerAngle
{
get { return (double)GetValue(MainPointerAngleProperty); }
set { SetValue(MainPointerAngleProperty, value); }
}
private static void MainPointerAngle_Changed(DependencyObject o, DependencyPropertyChangedEventArgs args)
{
ctlGauge thisClass = (ctlGauge)o;
thisClass.SetMainPointerAngle();
}
private void SetMainPointerAngle()
{
//Put Instance MainPointerAngle Property Changed code here
}
public ctlGauge()
{
InitializeComponent();
SetCurrentValue();
SetMaxValue();
}
private double GetValueAngle(double value)
{
double dAngle = 125 + (value * 29);
if (dAngle > 360)
{
dAngle -= 360;
if (dAngle > 56)
dAngle = 56;
}
else if (dAngle < 124)
dAngle = 124;
return dAngle;
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
名称空间时钟
{
///
///ctlClock.xaml的交互逻辑
///
公共部分类:UserControl
{
public static dependencProperty MaxValueProperty=dependencProperty.Register(“MaxValue”、typeof(double)、typeof(ctlguge)、new FrameworkPropertyMetadata(new PropertyChangedCallback(MaxValue_Changed));
公共双最大值
{
获取{return(double)GetValue(MaxValueProperty);}
set{SetValue(MaxValueProperty,value);}
}
私有静态void MaxValue_已更改(DependencyObject o、DependencyPropertyChangedEventArgs args)
{
ctlGauge thisClass=(ctlGauge)o;
thisClass.SetMaxValue();
}
私有void SetMaxValue()
{
MaxPointAngle=GetValueAngle(MaxValue);
}
public static dependencProperty CurrentValueProperty=dependencProperty.Register(“CurrentValue”、typeof(double)、typeof(ctlguge)、new FrameworkPropertyMetadata(new PropertyChangedCallback(CurrentValue_Changed));
公共双电流值
{
获取{return(double)GetValue(CurrentValueProperty
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 clock
{
/// <summary>
/// Interaction logic for ctlClock.xaml
/// </summary>
public partial class ctlGauge : UserControl
{
public static DependencyProperty MaxValueProperty = DependencyProperty.Register("MaxValue", typeof(double), typeof(ctlGauge), new FrameworkPropertyMetadata(new PropertyChangedCallback(MaxValue_Changed)));
public double MaxValue
{
get { return (double)GetValue(MaxValueProperty); }
set { SetValue(MaxValueProperty, value); }
}
private static void MaxValue_Changed(DependencyObject o, DependencyPropertyChangedEventArgs args)
{
ctlGauge thisClass = (ctlGauge)o;
thisClass.SetMaxValue();
}
private void SetMaxValue()
{
MaxPointAngle = GetValueAngle(MaxValue);
}
public static DependencyProperty CurrentValueProperty = DependencyProperty.Register("CurrentValue", typeof(double), typeof(ctlGauge), new FrameworkPropertyMetadata(new PropertyChangedCallback(CurrentValue_Changed)));
public double CurrentValue
{
get { return (double)GetValue(CurrentValueProperty); }
set { SetValue(CurrentValueProperty, value); }
}
private static void CurrentValue_Changed(DependencyObject o, DependencyPropertyChangedEventArgs args)
{
ctlGauge thisClass = (ctlGauge)o;
thisClass.SetCurrentValue();
}
private void SetCurrentValue()
{
MainPointerAngle = GetValueAngle(CurrentValue);
}
public static DependencyProperty MainPointerAngleProperty = DependencyProperty.Register("MainPointerAngle", typeof(double), typeof(ctlGauge), new FrameworkPropertyMetadata(new PropertyChangedCallback(MainPointerAngle_Changed)));
public static DependencyProperty MaxPointAngleProperty = DependencyProperty.Register("MaxPointAngle", typeof(double), typeof(ctlGauge), new FrameworkPropertyMetadata(new PropertyChangedCallback(MaxPointAngle_Changed)));
public double MaxPointAngle
{
get { return (double)GetValue(MaxPointAngleProperty); }
set { SetValue(MaxPointAngleProperty, value); }
}
private static void MaxPointAngle_Changed(DependencyObject o, DependencyPropertyChangedEventArgs args)
{
ctlGauge thisClass = (ctlGauge)o;
thisClass.SetMaxPointAngle();
}
private void SetMaxPointAngle()
{
//Put Instance MaxPointAngle Property Changed code here
}
public double MainPointerAngle
{
get { return (double)GetValue(MainPointerAngleProperty); }
set { SetValue(MainPointerAngleProperty, value); }
}
private static void MainPointerAngle_Changed(DependencyObject o, DependencyPropertyChangedEventArgs args)
{
ctlGauge thisClass = (ctlGauge)o;
thisClass.SetMainPointerAngle();
}
private void SetMainPointerAngle()
{
//Put Instance MainPointerAngle Property Changed code here
}
public ctlGauge()
{
InitializeComponent();
SetCurrentValue();
SetMaxValue();
}
private double GetValueAngle(double value)
{
double dAngle = 125 + (value * 29);
if (dAngle > 360)
{
dAngle -= 360;
if (dAngle > 56)
dAngle = 56;
}
else if (dAngle < 124)
dAngle = 124;
return dAngle;
}
}
}
<Window x:Class="clock.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:clock"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<local:ctlGauge CurrentValue="{Binding ElementName=sldPointerAngle, Path=Value}" MaxValue="{Binding ElementName=sldMaxAngle, Path=Value}" Grid.ColumnSpan="3" />
<TextBlock Text="Pointer Value:" HorizontalAlignment="Right" Grid.Row="1" />
<Slider Name="sldPointerAngle" Grid.Row="1" Grid.Column="1" Minimum="-1" Maximum="11" Value="0" />
<TextBlock Grid.Column="2" Grid.Row="1" Width="100" Text="{Binding ElementName=sldPointerAngle, Path=Value}" />
<TextBlock Text="Max Value:" HorizontalAlignment="Right" Grid.Row="2" />
<Slider Name="sldMaxAngle" Grid.Row="2" Minimum="0" Grid.Column="1" Maximum="10" Value="9" />
<TextBlock Grid.Column="2" Grid.Row="2" Width="100" Text="{Binding ElementName=sldMaxAngle, Path=Value}" />
</Grid>
</Window>
<UserControl x:Class="clock.ctlGauge"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:clock"
mc:Ignorable="d"
d:DesignHeight="256" d:DesignWidth="256" DataContext="{Binding RelativeSource={RelativeSource Self}}" >
<Viewbox>
<Grid Height="256" Width="256">
<Image Name="imgBack" Source="images/Yellowback.png" />
<Image Name="imgBigPointer" Source="images/Pointer1.png" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="{Binding MainPointerAngle}"/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
<Image Name="imgSmallPointer" Source="images/Pointer2.png" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="{Binding MaxPointAngle}"/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
<Image Name="imgBorder" Source="images/CircleBorder.png" />
<Image Name="imgCenterCover" Source="images/CenterCover.png" />
</Grid>
</Viewbox>
</UserControl>