在wp8中生成图像的反转(镜像)

时间:2015-06-01 11:04:10

标签: c# image windows-phone-8 bitmapimage

我将使用c#在窗口电话8中生成图像的镜像。我到现在为止尝试过的是这里。我的Xaml代码:

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
        <TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Button Name="submit" Grid.Row="0" Content="Select an Image" Tap="submit_Tap"/>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Image Name="mainImage" Stretch="Fill" Grid.Column="0" Height="500" Width="200"/>
            <Image Name="InvertedImage" Stretch="Fill" Grid.Column="1" Height="500" Width="200"/>
        </Grid>
        <Button Name="mirrorImage" Grid.Row="2" Content="Create Mirror Image" Tap="mirrorImage_Tap"/>
    </Grid>

`

我的c#代码:

private void submit_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
    PhotoChooserTask task = new PhotoChooserTask();
    task.Completed+=new EventHandler<PhotoResult>(task_Completed);
    task.Show();
}
BitmapImage mainImageSource = new BitmapImage();
private void task_Completed(object sender, PhotoResult e)
{
    if (e.TaskResult == TaskResult.OK)
    {
        mainImageSource.SetSource(e.ChosenPhoto);
        mainImage.Source = mainImageSource;
    }
}

private void mirrorImage_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
    InvertedImage.Source = mainImageSource;
}
}

在mirrorImage_Tap中。我要在InvertedImage的源代码中设置反转图像。感谢帮助。

1 个答案:

答案 0 :(得分:2)

尝试以下代码

    <Grid Grid.Row="1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Image Name="mainImage" Stretch="Fill" Grid.Column="0" Height="500" Width="200"/>
        <Image Name="InvertedImage" Stretch="Fill" Grid.Column="1" RenderTransformOrigin="0.5,0.5"Height="500" Width="200">
        <Image.RenderTransform>
                <CompositeTransform ScaleX="-1"/>
            </Image.RenderTransform>
        </Image>
    </Grid>

我认为图片上的<CompositeTransform ScaleX="-1"/>将为您完成这项工作。