2010-06-28 95 views
1

我有大小800×600的圖像,我需要表現出與偏移x = 12和y 12WPF圖像偏移

我創建該刷小圖像碎片90x30,但我不知道如何使抵消。

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; 

任何人都知道該怎麼做?

回答

4

我找到了下一個解決方案:將圖像添加爲網格,並設置網格屬性ClipToBounds = true。 然後通過改變圖像邊距我們可以設置圖像偏移量。