wpf或HTML5里插入图片,在图片上做标记,点击标记触发事件

2025-03-12 03:00:50
推荐回答(1个)
回答1:

WPF用RenderTransform实现,随便做了个,代码如下。


XAML

        xmlns="

        xmlns:x="

        Title="MainWindow"
        Height="350"
        Width="525">
    
        
            
                
                    
                    
                    
                

            

        

                            Height="20">
                                Content="缩小"
                    Click="btnScale1_Click" />
                                Content="放大"
                    Click="btnScale2_Click" />
                                Content="左转"
                    Click="btnRotation1_Click" />
                                Content="右转"
                    Click="btnRotation2_Click" />
                                Content="左移"
                    Click="btnMove1_Click" />
                                Content="右移"
                    Click="btnMove2_Click" />
                                Content="上移"
                    Click="btnMove3_Click"/>
                                Content="下移"
                    Click="btnMove4_Click" />
        
    


CS如下

    namespace WpfApplication3
{
    /// 
    /// MainWindow.xaml 的交互逻辑
    /// 

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
        }

        private bool _ischecked = false;
        public bool IsChecked
        {
            get
            {
                return _ischecked;
            }
        }

        private void btnScale1_Click(object sender, RoutedEventArgs e)
        {
            st.CenterX = image.ActualWidth / 2;
            st.CenterY = image.ActualHeight / 2;
            st.ScaleX -= 0.1;
            st.ScaleY -= 0.1;
        }

        private void btnScale2_Click(object sender, RoutedEventArgs e)
        {
            st.CenterX = image.ActualWidth / 2;
            st.CenterY = image.ActualHeight / 2;
            st.ScaleX += 0.1;
            st.ScaleY += 0.1;
        }

        private void btnRotation1_Click(object sender, RoutedEventArgs e)
        {
            rt.CenterX = image.ActualWidth / 2;
            rt.CenterY = image.ActualHeight / 2;
            rt.Angle -= 10;
        }

        private void btnRotation2_Click(object sender, RoutedEventArgs e)
        {
            rt.CenterX = image.ActualWidth / 2;
            rt.CenterY = image.ActualHeight / 2;
            rt.Angle += 10;
        }

        private void btnMove1_Click(object sender, RoutedEventArgs e)
        {
            tt.X -= 10;
        }

        private void btnMove2_Click(object sender, RoutedEventArgs e)
        {
            tt.X += 10;
        }

        private void btnMove3_Click(object sender, RoutedEventArgs e)
        {
            tt.Y -= 10;
        }

        private void btnMove4_Click(object sender, RoutedEventArgs e)
        {
            tt.Y += 10;
        }
    }
}