2014-09-09 3 views
0

저는 캔버스에 이미지가 있습니다. 캔버스의 크기를 이미지의 크기로 설정합니다. 캔버스를 원하는 크기로 작게 만듭니다. 이제 이미지에 그림자 효과를 적용하려고하지만 캔버스 외부에 있기 때문에 일부가 잘립니다. 그래서 이미지 크기를 조정하지 않고 캔버스를 늘려야합니다.캔버스 내부의 이미지 크기를 조정하지 않고 캔버스 크기 조정

수동으로 이미지의 크기를 조절할 수 있었지만 제대로 작동했지만 이미지를 만지지 않고 대신 캔버스 크기를 늘 렸습니다.

여기 제가 시도했지만, 이미지는 캔버스와 함께 조절됩니다. 당신이 왼쪽 상단 모서리에 기본적으로 배치됩니다 캔버스에 넣어 때문에

<Canvas ClipToBounds="True" Name="ImageDropShadowThumbnail" Height="{Binding Height}" Width="{Binding Width}"> 
    <Canvas.LayoutTransform> 
     <ScaleTransform ScaleX="{Binding Value, ElementName=ScaleXSlider}" ScaleY="{Binding Value, ElementName=ScaleYSlider}" CenterX="{Binding CenterX}" CenterY="{Binding CenterY}"/> 
    </Canvas.LayoutTransform> 
    <Image Source="{Binding Name}" Height="{Binding Height}" Width="{Binding Width}" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Center"> 
     <Image.Effect> 
      <DropShadowEffect BlurRadius="{Binding Value, ElementName=BlurRadiusSlider}" Direction="{Binding Value, ElementName=DirectionSlider}" Opacity="{Binding Value, ElementName=OpacitySlider}" ShadowDepth="{Binding Value, ElementName=ShadowDepthSlider}"/> 
     </Image.Effect> 
    </Image> 

</Canvas> 
+2

캔버스 폭에 변환기를 추가하고 높이 이미지에 바인딩 크기와 변환기에 dropshadoweffect를 볼 수 있도록 예를 들어 약간의 공간 + 30을 추가하십시오. – Maximus

답변

1
<Canvas Background="CadetBlue" Width="{Binding ElementName=Image1, Path=Width, Converter={StaticResource HeightConverter}}" 
     Height="{Binding ElementName=Image1, Path=Height, Converter={StaticResource HeightConverter}}"> 
    <Image Name="Image1" Source="1.jpg" Width="150" Height="150" Stretch="Fill"/> 
</Canvas> 

[ValueConversion(typeof(double), typeof(double))] 
public class HeightConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
     double result; 
     Double.TryParse(value.ToString(), out result); 
     return result + 20.0; 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 
} 

그래서 위해 Canvas.LEFT/톱 등을 설정해야

관련 문제