سؤال

لدي صورة بحجم 800 × 600 وأحتاج إلى إظهار جزء صغير من الصورة 90x30 مع إزاحة x = 12 و y 12.

أقوم بإنشاء فرشاة لذلك ولكني لا أعرف كيفية إزاحة.

 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;

أي شخص يعرف كيف يفعل ذلك؟

هل كانت مفيدة؟

المحلول

لقد وجدت الحل التالي: أضف الصورة كطفل إلى الشبكة وتعيين cliptObounds = True. ثم عن طريق تغيير هامش الصورة يمكننا تعيين إزاحة الصورة.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top