PageRenderTime 26ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/Visual Studio 2008/VBSL3WriteableBitmap/Screenshot.xaml

#
XAML | 49 lines | 49 code | 0 blank | 0 comment | 0 complexity | 8ddb4dfe1cc73ee731e806b304c9669d MD5 | raw file
  1. <UserControl
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Class="VBSL3WriteableBitmap.Screenshot"
  5. mc:Ignorable="d" d:DesignWidth="479" d:DesignHeight="375" Loaded="UserControl_Loaded">
  6. <UserControl.Resources>
  7. <Storyboard x:Name="sb" RepeatBehavior="Forever">
  8. <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="uiElementSource" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Duration="00:00:00.0010000">
  9. <EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
  10. </DoubleAnimationUsingKeyFrames>
  11. <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="uiElementSource" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationX)">
  12. <EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
  13. <EasingDoubleKeyFrame KeyTime="00:00:05" Value="360"/>
  14. </DoubleAnimationUsingKeyFrames>
  15. <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="uiElementSource" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
  16. <EasingDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
  17. <EasingDoubleKeyFrame KeyTime="00:00:05" Value="0.5"/>
  18. </DoubleAnimationUsingKeyFrames>
  19. <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="uiElementSource" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
  20. <EasingDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
  21. <EasingDoubleKeyFrame KeyTime="00:00:05" Value="0.5"/>
  22. </DoubleAnimationUsingKeyFrames>
  23. </Storyboard>
  24. </UserControl.Resources>
  25. <StackPanel x:Name="LayoutRoot" Background="White">
  26. <TextBlock Text="WriteableBitmap is also capable of creating screenshots from non-bitmap images. However, there're some limitations. In the following sample, the above rectangle is a vector graphic (in a Canvas). The below one is a screenshot created rapidly using the Canvas. As you can see, the ScaleTransform and ShaderEffect are respected, but the Projection is lost." TextWrapping="Wrap"/>
  27. <Canvas x:Name="uiElementSource" Height="300" Width="300" HorizontalAlignment="Center" RenderTransformOrigin="0.5,0.5">
  28. <Canvas.Projection>
  29. <PlaneProjection/>
  30. </Canvas.Projection>
  31. <Canvas.RenderTransform>
  32. <TransformGroup>
  33. <ScaleTransform/>
  34. <SkewTransform/>
  35. <RotateTransform/>
  36. <TranslateTransform/>
  37. </TransformGroup>
  38. </Canvas.RenderTransform>
  39. <Rectangle Fill="Red" Height="200" Width="200" Canvas.Left="50" Canvas.Top="50">
  40. <Rectangle.Effect>
  41. <DropShadowEffect Color="#FF0095FF"/>
  42. </Rectangle.Effect>
  43. </Rectangle>
  44. </Canvas>
  45. <Image x:Name="img" Height="300" Width="300" Stretch="None"/>
  46. <TextBlock Text="Save the screenshot to a bmp file. Note the Projection is lost, and all empty pixels are rendered in black (000000), due to the limitation of WriteableBitmap." TextWrapping="Wrap"/>
  47. <Button x:Name="SaveFileButton" Content="Save" Click="SaveFileButton_Click"/>
  48. </StackPanel>
  49. </UserControl>