Ugrás a tartalomhoz

.NET Programming Technologies

Gergely Kovásznai, Csaba Biró

Eszterházy Károly College

TransformGroup

TransformGroup

TransformGroup has to be used if the wanted effect cannot be achieved.

<TransformGroup>

     Gyerekelemek

</TransformGroup>

Example VIII.5 TransformGroup 1

VIII.6. TransformGroup

<Image Width="90" Height="60" Source="car.jpg">

       <Image.RenderTransform>

           <TransformGroup>

              <MatrixTransform>

                     <MatrixTransform.Matrix >

                         <Matrix OffsetX="10" OffsetY="1" M11="3" M12="2"/>

                     </MatrixTransform.Matrix>

              </MatrixTransform>

              <RotateTransform Angle="30"/>

                   <TranslateTransform X="-20" Y="-110"/>

          </TransformGroup>

      </Image.RenderTransform>

</Image>

Example VIII.7 TransformGroup 2

VIII.7. TransformGroup

Code-behind:

namespace TranszformGroup

{

/// <summary>

/// Interaction logic for Window1.xaml

/// </summary>

public partial class Window1 : Window

{

     TransformGroup tg = new TransformGroup();

     RotateTransform rt = new RotateTransform();

     ScaleTransform st = new ScaleTransform();

     TranslateTransform ttr = new TranslateTransform();

     SkewTransform skt = new SkewTransform();

public Window1()

{

    InitializeComponent();

}

private void Window_Loaded(object sender, RoutedEventArgs e)

{

   try

    {

       BitmapImage bi = new BitmapImage();

       bi.BeginInit();

bi.UriSource = new Uri(System.Windows.Forms.Application.StartupPath + @"\kutya.jpg",       UriKind.RelativeOrAbsolute);

bi.EndInit();

image1.Source = bi;

}

catch (FileNotFoundException)

{

MessageBox.Show("Hiba! A bemutatóhoz szükséges kép nem nyitható meg. Kérem,       válassza ki manuálisan a Transzformáció fül Megnyitás gombjával!");

}

}

private void Megnyit_Click(object sender, RoutedEventArgs e)

{

System.Windows.Forms.OpenFileDialog OpenFile = new       System.Windows.Forms.OpenFileDialog();

OpenFile.CheckFileExists = true;

OpenFile.FileName = String.Empty;

OpenFile.Filter = "Képfájlok(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|Összes fájl         (*.*)|*.*";

   if (OpenFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)

     {

        BitmapImage bi = new BitmapImage();

        bi.BeginInit();

        bi.UriSource = new Uri(OpenFile.FileName, UriKind.RelativeOrAbsolute);

        bi.EndInit();

        image1.Source = bi;

      }

}

private void forgatasSlider_ValueChanged(object sender,

RoutedPropertyChangedEventArgs<double> e)

{

rt.Angle = forgatasSlider.Value;

rt.CenterX = image1.ActualWidth / 2;

rt.CenterY = image1.ActualHeight / 2;

tg.Children.Add(rt);

image1.RenderTransform = tg;

}