wpfimagegridoffsetimagebrush

WPF image thumbnail with the offset


I have an image 800x600 and I would show a thumbnail 90x30 with some offset x=12 and y 12.

I have created a brush but I am struggling to apply an 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;

I would appreciate any suggestions.


Solution

  • There is a hacky solution for this problem: