silverlight图片旋转、放大、缩小

本文详细介绍了如何在Silverlight 4中使用Image组件实现图片的缩放、放大和旋转功能,包括后台代码实现和关键步骤解析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<UserControl x:Class="TestStoryBoard.Test"
    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"
    mc:Ignorable="d">
    <Grid x:Name="mainCanvas" Height="404" Width="733" Background="Black">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="Auto" MinWidth="95" />
        </Grid.ColumnDefinitions>
        <Grid x:Name="grid1" Height="400" Width="636" HorizontalAlignment="Center" VerticalAlignment="Center">
            <Image x:Name="image1"
               Source="orton-nomercy07.jpg"
               Stretch="Uniform"
               HorizontalAlignment="Center" VerticalAlignment="Center"
               RenderTransformOrigin="0.5, 0.5">
                <Image.RenderTransform>
                    <TransformGroup>
                        <RotateTransform x:Name="Rotator"/>
                        <ScaleTransform x:Name="Scale" />
                    </TransformGroup>
                </Image.RenderTransform>
            </Image>
        </Grid>
        <StackPanel Grid.Column="1" Margin="0,2,3,0" VerticalAlignment="Top" Height="81">
            <Button x:Name="ZoomInButton" Click="ZoomInButton_Click" Content="Zoom In" Height="25" FontWeight="Bold" FontStyle="Italic" >
              <Button.Background>
                     <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                           <GradientStop Color="Black" Offset="0"/>
                           <GradientStop Color="#FFE21E1E" Offset="1"/>
                     </LinearGradientBrush>
              </Button.Background>
            </Button>
            <Button x:Name="ZoomOutButton" Click="ZoomOutButton_Click" Content="Zoom Out" FontWeight="Bold" FontStyle="Italic" >
              <Button.Background>
                     <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                           <GradientStop Color="Black" Offset="0"/>
                           <GradientStop Color="#FFAF1F1F" Offset="1"/>
                     </LinearGradientBrush>
              </Button.Background>
            </Button>
            <Button x:Name="RotateButton" Click="RotateButton_Click" Content="Rotate" FontWeight="Bold" >
              <Button.Background>
                     <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                           <GradientStop Color="Black" Offset="0"/>
                           <GradientStop Color="#FFB41C1C" Offset="1"/>
                     </LinearGradientBrush>
              </Button.Background>
            </Button>
        </StackPanel>
    </Grid>
</UserControl>

 

后台代码:


private double angle = 90;

private void ZoomInButton_Click(object sender, RoutedEventArgs e)
        {
            Scale.ScaleX += 0.25;
            Scale.ScaleY += 0.25;
        }
 
        private void ZoomOutButton_Click(object sender, RoutedEventArgs e)
        {
            if (Scale.ScaleX > 0.25)
            {
                Scale.ScaleX -= 0.25;
                Scale.ScaleY -= 0.25;
            }
        }

        private void RotateButton_Click(object sender, RoutedEventArgs e)
        {
            Rotator.Angle += angle;
            if (Rotator.Angle == 360)
                Rotator.Angle = 0;
        }


 本篇文章来源于 空刃软件坊 原文链接:http://dy-wizard.com/Tutorial/silverlight/How%20to%20use%20Image%20Zoom%20In,%20Zoom%20Out,%20and%20Rotate%20in%20Silverlight%204/How%20to%20use%20Image%20Zoom%20In,%20Zoom%20Out,%20and%20Rotate%20in%20Silverlight%204.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值