2011-04-23 3 views
0

저는 Silverlight 응용 프로그램에서 작업 중이며 위쪽, 아래쪽, 왼쪽, 오른쪽 등의 이미지를 패닝하여 이미지를 패닝 할 수 있습니다.Silverlight Image Panning

나는 픽셀 쉐이딩을 사용 했었지만 나는 이것의 성공이 아니다.

덕분에 ..

답변

0

당신은 또한 드래그의 혼합 동작을 볼 수 있었다 this sample

에서보세요.

0

이것은 나를 위해 일했습니다. 이 창을 사용하여 확대 된 이미지를 미리 볼 수 있으며 이미지를보다 관련성이 높은 섹션으로 이동시킬 수 있습니다. 이미지의 하단 부분. 윈도우의 코드가 (뒤) 다음과 같습니다

BitmapImage BMP = /* resolve the bitmap */; 

PreviewImageWindow.Execute(BMP); 

:

창을 사용합니다.

using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Input; 
using System.Windows.Media.Imaging; 

namespace ITIS.Controls.LinearViewer.Windows { 

public partial class PreviewImageWindow : ChildWindow { 

    /// <summary>See Execute</summary> 
    PreviewImageWindow() { 
     InitializeComponent(); 
    } 

    private void OKButton_Click(object sender, RoutedEventArgs e) { 
     this.DialogResult = true; 
    } 

    private void CancelButton_Click(object sender, RoutedEventArgs e) { 
     this.DialogResult = false; 
    } 

    static public void Execute(BitmapImage imageSource) { 

     PreviewImageWindow Window = new PreviewImageWindow(); 

     Window.Image.Source = imageSource; 

     /* don't allow the window to grow larger than the image */ 
     Window.MaxWidth = imageSource.PixelWidth; 
     Window.MaxHeight = imageSource.PixelHeight; 

     Window.Show(); 
    } 

    private void ChildWindow_KeyDown(object sender, KeyEventArgs e) { 

     if (e.Key == Key.Escape) { 

      DialogResult = false; 
     } 
    } 

    Point? _lastPoint; 

    bool _isMouseDown; 

    private void image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { 

     ((Image)sender).CaptureMouse(); 

     _isMouseDown = true; 

     ShowCursor(e.GetPosition(Canvas)); 

     _lastPoint = e.GetPosition((Image)sender); 
    } 

    private void image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { 

     ((Image)sender).ReleaseMouseCapture(); 

     _isMouseDown = false; 

     ShowCursor(e.GetPosition(Canvas)); 

     _lastPoint = null; 
    } 

    private void image_MouseMove(object sender, MouseEventArgs e) { 

     if (_lastPoint != null) { 

      Image Image = (Image)sender; 

      Point CurrentPoint = e.GetPosition(Image); 

      double 
       XDelta = CurrentPoint.X - _lastPoint.Value.X, 
       YDelta = CurrentPoint.Y - _lastPoint.Value.Y; 

      _lastPoint = null; 

      if (XDelta != 0) { 
       double NewLeft = Canvas.GetLeft(Image) + XDelta; 
       if (NewLeft <= 0 && NewLeft + Image.ActualWidth >= Canvas.ActualWidth) { 
        Canvas.SetLeft(Image, NewLeft); 
       } 
      } 

      if (YDelta != 0) { 
       double NewTop = Canvas.GetTop(Image) + YDelta; 
       if (NewTop <= 0 && NewTop + Image.ActualHeight >= Canvas.ActualHeight) { 
        Canvas.SetTop(Image, NewTop); 
       } 
      } 

      _lastPoint = e.GetPosition(Image); 
     } 

     Point CanvasPoint = e.GetPosition(Canvas); 
     ShowCursor(CanvasPoint); 
    } 

    private void Canvas_Loaded(object sender, RoutedEventArgs e) { 

     TryDefaultImageToTop(); 
    } 

    void TryDefaultImageToTop() { 

     if (Image == null || Canvas == null) { return; } 

     /* move the image up so we can focus on the road? user-friendly since we are most-likely going to look at the road, not the horizon or top - half */ 
     if (!_initialized) { 

      _initialized = true; 

      Canvas.SetTop(Image, Canvas.ActualHeight - Image.ActualHeight); 
      Canvas.SetLeft(Image, (Canvas.ActualWidth - Image.ActualWidth)/2); 
     } 
    } 

    bool _initialized; 

    private void image_Loaded(object sender, RoutedEventArgs e) { 

     TryDefaultImageToTop(); 
    } 

    private void image_MouseEnter(object sender, MouseEventArgs e) { 

     imgOpenHand.Visibility = Visibility.Visible; 
     imgClosedHand.Visibility = Visibility.Collapsed; 

     ShowCursor(e.GetPosition(Canvas)); 
    } 

    void ShowCursor(Point point) { 

     if (_isMouseDown) { 
      imgClosedHand.Visibility = Visibility.Visible; 
      imgOpenHand.Visibility = Visibility.Collapsed; 

      Canvas.SetLeft(imgClosedHand, point.X); 
      Canvas.SetTop(imgClosedHand, point.Y); 
     } 
     else { 
      imgClosedHand.Visibility = Visibility.Collapsed; 
      imgOpenHand.Visibility = Visibility.Visible; 

      Canvas.SetLeft(imgOpenHand, point.X); 
      Canvas.SetTop(imgOpenHand, point.Y); 
     } 
    } 

    private void image_MouseLeave(object sender, MouseEventArgs e) { 
     imgOpenHand.Visibility = Visibility.Collapsed; 
     imgClosedHand.Visibility = Visibility.Collapsed; 
    } 
} 

}

창에 대한 XAML은 다음과 같습니다 :

<controls:ChildWindow 
x:Class="ITIS.Controls.LinearViewer.Windows.PreviewImageWindow" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" 
Background="#383838" Foreground="WhiteSmoke"  
Title="Preview" Margin="50" 
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
KeyDown="ChildWindow_KeyDown"  
> 
<Grid x:Name="LayoutRoot" Margin="0" Cursor="None" IsHitTestVisible="True"> 
    <Grid.RowDefinitions> 
     <RowDefinition /> 
     <RowDefinition Height="Auto" /> 
    </Grid.RowDefinitions> 
    <Canvas Cursor="None" IsHitTestVisible="True" x:Name="Canvas" Loaded="Canvas_Loaded"> 
     <Image Source="{Binding ImageSource}" x:Name="Image" 
       Cursor="None" Loaded="image_Loaded" 
       MouseLeftButtonDown="image_MouseLeftButtonDown" 
       MouseLeftButtonUp="image_MouseLeftButtonUp" 
       MouseMove="image_MouseMove" 
       MouseEnter="image_MouseEnter" 
       MouseLeave="image_MouseLeave" 
       IsHitTestVisible="True" 
       /> 
     <Image Style="{StaticResource HandOpenImage}" x:Name="imgOpenHand" 
       Visibility="Collapsed" IsHitTestVisible="False" 
       /> 
     <Image Style="{StaticResource HandClosedImage}" x:Name="imgClosedHand" 
       Visibility="Collapsed" IsHitTestVisible="False" 
       /> 
    </Canvas>   
</Grid>  

몇 잡는다 /이 코드에 대한 코멘트 :

  1. 네임 스페이스에 대한 이 창은 "ITIS.Controls.LinearVie wer.Windows ", 네임 스페이스를 시스템에서보다 관련성 높은 것으로 변경하십시오.
  2. 정상적인 커서 이미지는 OpenHand하고 마우스 버튼이 눌러져있을 때, HandClosed
  3. 나는 글로벌 응용 프로그램 전체 리소스 사전에있는 이미지의 스타일로 이미지 변경 :

(OPEN 이미지 스타일)

<Style TargetType="Image" x:Key="HandOpenImage"> 
    <Setter Property="Source" Value="/ITIS.Controls.LinearViewer.Silverlight;component/Images/HandOpen.png" /> 
    <Setter Property="Width" Value="16" /> 
    <Setter Property="Height" Value="16" /> 
</Style> 

(CLOSED 이미지 스타일)

<Style TargetType="Image" x:Key="HandClosedImage"> 
    <Setter Property="Source" Value="/ITIS.Controls.LinearViewer.Silverlight;component/Images/HandClosed.png" /> 
    <Setter Property="Width" Value="13" /> 
    <Setter Property="Height" Value="11" /> 
</Style> 
  1. 이 미리보기는 이미지의 아래쪽 절반에 포커스를두고 시작하려고 시도하지만 위쪽 절반은 시작하지 않습니다.

희망이 도움이됩니다. 몇 가지 염증을 없애기까지는 어느 정도 시간이 걸렸습니다.