views:

24

answers:

1

I have image with size 800x600 and i need to show small image fragment 90x30 with offset x=12 and y 12.

I create brush for that but i dont know how to make offset.

 var source = new ImageBrush(groundSource);
                source.Stretch = Stretch.None;
                source.AlignmentX = AlignmentX.Left;
                source.AlignmentY = AlignmentY.Top;
                source.RelativeTransform = new TranslateTransform(0.5, 0);
                var grid = new Grid();
                grid.ClipToBounds = true;
                grid.Background = source;
                grid.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                grid.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                grid.Margin = new System.Windows.Thickness(12, 12, 0, 0);
                grid.Width = SpriteSize.SpriteWidht + 33;
                grid.Height = SpriteSize.SpriteHeight;
                grid.SnapsToDevicePixels = true;

Anybody knows how to do that?

+1  A: 

I found next solution: Add image as child to Grid and set grid property ClipToBounds=true. And then by changing image margin we can set image offset.

Evgeny