简体   繁体   中英

round robin image rotation what is the best way to do in WPF

I am looking to find the best way to do this in wpf. I already asked this question and got an answer which implement it in opencv. round robin image rotation what is the best way to do in opencv

What is the best way to do this in wpf.
Apparently I can create a writableBitmap and copy the pixels manually, but I don't think it is the best way to do this.

Edit 1

To clarify what I am asking: I like to implement the same algorithm that suggested in this SO question ( round robin image rotation what is the best way to do in opencv ) using WPF.

What is the best way to do this in WPF which is efficient (memory and speed).

You can use an ImageBrush to draw on a rectangle and adjust the ViewPort property of the brush to slide the image. If you wanted to do an animation with this, here is a sample XAML in WPF which uses animation to automatically adjust the viewport property of the brush and perform a slide animation. Hope this is helpful.

<Window x:Class="TestWpfApplication.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
    <Grid>
        <Rectangle>
            <Rectangle.Fill>
                <DrawingBrush x:Name="MyBrush" Viewport="0,0,1,1" TileMode="Tile">
                    <DrawingBrush.Drawing>
                        <DrawingGroup>
                            <GeometryDrawing>
                                <GeometryDrawing.Geometry>
                                    <GeometryGroup>
                                        <RectangleGeometry Rect="0,0,100,100" />
                                    </GeometryGroup>
                                </GeometryDrawing.Geometry>
                                <GeometryDrawing.Brush>
                                    <ImageBrush ImageSource="lSXfX.png" />
                                </GeometryDrawing.Brush>
                            </GeometryDrawing>
                        </DrawingGroup>
                    </DrawingBrush.Drawing>
                </DrawingBrush>
            </Rectangle.Fill>
            <Rectangle.Triggers>
                <EventTrigger RoutedEvent="Rectangle.Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <RectAnimation
                            Storyboard.TargetName="MyBrush" 
                            Storyboard.TargetProperty="Viewport"
                            From="0 0 1 1" To="1 0 1 1" Duration="0:0:10"
                            RepeatBehavior="Forever" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Rectangle.Triggers>
        </Rectangle>
    </Grid>
</Window>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM