Silverlight 3 - Pixel Shader

Pazartesi, 23 Mart 2009 19:07 by ikivanc
Silverlight 3 ile birlikte gelen yeniliklerden birisi de Pixel Shader. Pixel Shader la birlikte Blur ve Drop Shadow effectleri birlikte gelmekte. Bunların yanında istediğimiz effectleri kendimiz yazarak kullanma imkanına da sahibiz.

System.Windows.Media.Effects namespace'inde bulunmaktadır.

Blur effecti,nesnede bulanıklık vermeye yarar ve bulanıklık derecesini de kendimiz seçebiliriz.
 
Hangi elementi kullanıyorsak onun altında "Element.Effect" içerisine <BlurEffect Radius="1"/> şeklinde yazılarak Blur effecti verilebiliriz.

<Image Source="joneal.jpg" Margin="129,8,160,0" VerticalAlignment="Top" Height="242">

    <Image.Effect>

        <BlurEffect Radius="0"/>

    </Image.Effect>

</Image>




Radius ise bulanıklık derecesini belirtmektedir ve artırdığımızda de değişikliği gözle görebiliriz.

Uygulamamıza slider atarak, slider'ı hareket ettirdikçe 0-10 arasındaki double değeri bulanıklık derecesi olarak fotoğrafımıza veren bir uygulama yapalım.

MainControl.xaml

<UserControl

    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"

    x:Class="MediaEffect.MainControl"

    Width="489" Height="256">

 

    <Grid x:Name="LayoutRoot" Background="White">

        <Image x:Name="image_jermaine" Source="joneal.jpg" Margin="23,0,0,0" VerticalAlignment="Top" Height="242" Width="200" HorizontalAlignment="Left"/> 

        <TextBox x:Name="textbox_blur" Height="23" HorizontalAlignment="Right" Margin="0,0,60,55""Bottom" Width="172" Text="" TextWrapping="Wrap" IsEnabled="True" IsReadOnly="True"/>        

        <Slider x:Name="blurslider" HorizontalAlignment="Right" Margin="0,0,60,25" Width="172""Bottom" Height="26"/>
    </Grid>

</UserControl>



MainControl.xaml.cs

    1 using System;

    2 using System.Windows;

    3 using System.Windows.Controls;

    4 using System.Windows.Documents;

    5 using System.Windows.Ink;

    6 using System.Windows.Input;

    7 using System.Windows.Media;

    8 using System.Windows.Media.Effects;

    9 using System.Windows.Media.Animation;

   10 using System.Windows.Shapes;

   11 

   12 namespace MediaEffect

   13 {

   14     public partial class MainControl : UserControl

   15     {

   16         public MainControl()

   17         {

   18             // Required to initialize variables

   19             InitializeComponent();

   20             blurslider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(blurslider_ValueChanged);

   21         }

   22 

   23         void blurslider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)

   24         {

   25             textbox_blur.Text = blurslider.Value.ToString();

   26             BlurEffect bulanik = new BlurEffect();

   27             bulanik.Radius = blurslider.Value;

   28             image_jermaine.Effect = bulanik;

   29         }

   30     }

   31 }





DropShadow

DropShadowEffect de adından anlaşılacağı gibi nesnenin altına gölge verilmesini sağlar

        <Image x:Name="image_jermaine" Source="joneal.jpg" Margin="23,0,0,0" VerticalAlignment="Top" Height="242" Width="200" HorizontalAlignment="Left"

            <Image.Effect>

                <DropShadowEffect Color="Yellow" Opacity="1" ShadowDepth="3"></DropShadowEffect>

            </Image.Effect>

        </Image>


Image.effect'in altında yazdıktan sonra tıkladığımızda properties penceresinde 5 tane değiştirebileceğimiz özelliği gelecektir bu effectin. Bunlardan dilediğimizi değiştirerek istediğimiz effecti verebiliriz.



Bu effectler sadece fotoğraflarda değil tüm silverlight bileşenlerde kullanılabilir.



Takıldığınız, sormak istediğiniz veya düzeltmek istediğiniz yerleri ibrahim.kivanc@msakademik.net mail adresime iletebilirsiniz.

Yorumlar

Yorum ekle


 

  Country flag

biuquote
  • Yorum
  • Canlı önizleme
Loading