Beispiel #1
0
        private void buttonLoadTemplate_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.FileName   = "MyWatermarks";
            dlg.DefaultExt = ".xml";
            dlg.Filter     = "Watermark templates (.xml)|*.xml";

            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                string        path   = dlg.FileName;
                XmlSerializer reader = new XmlSerializer(typeof(TextWatermarkSerializationHelper[]));
                TextWatermarkSerializationHelper[] th = null;
                try
                {
                    System.IO.StreamReader file = new System.IO.StreamReader(path);
                    th = (TextWatermarkSerializationHelper[])reader.Deserialize(file);
                }
                catch (Exception)
                { }
                if (th != null)
                {
                    RemoveAllAdornersFromLabelWatermarks();
                    textWatermarks = new TextWatermarkListWithSerchByUiLabel();
                    foreach (TextWatermarkSerializationHelper h in th)
                    {
                        System.Drawing.Color c = System.Drawing.Color.FromArgb(h.colorArgb);
                        TextWatermark        t = new TextWatermark(h.text,
                                                                   new System.Windows.Media.FontFamily(h.fontFamilyName),
                                                                   System.Windows.Media.Color.FromArgb(c.A, c.R, c.G, c.B),
                                                                   h.height,
                                                                   h.angle,
                                                                   h.opacity,
                                                                   h.x,
                                                                   h.y);

                        t.UiLabelOnImageInCanvas.MouseLeftButtonDown += WatermarkLabelOnCanvasTouched;
                        t.UiLabelOnImageInCanvas.Cursor = Cursors.Hand;
                        t.SetLabelGeometryAccordingToImageAndCanvas(imagePreview.Width, imagePreview.Height, canvasMain.ActualWidth, canvasMain.ActualHeight);
                        canvasMain.Children.Add(t.UiLabelOnImageInCanvas);

                        textWatermarks.Add(t);
                    }

                    AddAdornerToWatermarkLabel(textWatermarks[textWatermarks.Count - 1]);
                    tabItemTextWatermarks.DataContext = textWatermarks[textWatermarks.Count - 1];
                }
            }
        }
Beispiel #2
0
        private void AddNewWatermark()
        {
            RemoveAllAdornersFromLabelWatermarks();

            TextWatermark t = new TextWatermark((string)Application.Current.FindResource("newWatermarkText"),
                                                new System.Windows.Media.FontFamily("Arial"), Colors.Red, 10, 0, 70, 3, 3);

            //selection
            t.UiLabelOnImageInCanvas.MouseLeftButtonDown += WatermarkLabelOnCanvasTouched;
            t.UiLabelOnImageInCanvas.Cursor = Cursors.Hand;
            t.SetLabelGeometryAccordingToImageAndCanvas(imagePreview.Width, imagePreview.Height, canvasMain.ActualWidth, canvasMain.ActualHeight);
            canvasMain.Children.Add(t.UiLabelOnImageInCanvas);

            AddAdornerToWatermarkLabel(t);

            textWatermarks.Add(t);
            tabItemTextWatermarks.DataContext = t;
        }