private void button1_Click(object sender, RoutedEventArgs e) { selCanv.InvalidateVisual(); Microsoft.Win32.SaveFileDialog savedialog = new Microsoft.Win32.SaveFileDialog(); savedialog.Title = "Сохранить картинку как ..."; savedialog.OverwritePrompt = true; savedialog.CheckPathExists = true; savedialog.Filter = "AC File(*.ac)|*.ac|" + "Bitmap File(*.bmp)|*.bmp|" + "GIF File(*.gif)|*.gif|" + "JPEG File(*.jpg)|*.jpg|" + "TIF File(*.tif)|*.tif|" + "PNG File(*.png)|*.png"; if (savedialog.ShowDialog() == true) { string fileName = savedialog.FileName; string strFilExtn = fileName.Remove(0, fileName.Length - 3); // Save file switch (strFilExtn) { case "bmp": CreateSaveBitmap(selCanv, fileName); break; case "jpg": CreateSaveBitmap(selCanv, fileName); break; case "gif": CreateSaveBitmap(selCanv, fileName); break; case "tif": CreateSaveBitmap(selCanv, fileName); break; case "png": CreateSaveBitmap(selCanv, fileName); break; case ".ac": ObjSer os = new ObjSer(); foreach (Image pic in pictureBox1) { Point relativePoint = pic.TransformToAncestor(this).Transform(new Point(0, 0)); SerPic sp = new SerPic(relativePoint.X, relativePoint.Y, pic.Width, pic.Height, ImageToString(pic.Source)); os.AddToPicList(sp); } foreach (TextBox text in textList) { Point relativePoint = text.TransformToAncestor(this).Transform(new Point(0, 0)); SerText st = new SerText(relativePoint.X, relativePoint.Y, text.FontFamily.Source, text.FontSize, text.Foreground.ToString(), text.Text); os.AddToTextList(st); } foreach (Grid table in gridList) { List <string> text = new List <string>(); foreach (TextBox t in table.Children) { text.Add(t.Text); } Point relativePoint = table.TransformToAncestor(this).Transform(new Point(0, 0)); SerGrid sg = new SerGrid(relativePoint.X, relativePoint.Y, table.RowDefinitions.Count, table.ColumnDefinitions.Count / table.RowDefinitions.Count, text); os.AddToGridList(sg); } Stream TestFileStream = File.Create(fileName); BinaryFormatter serializer = new BinaryFormatter(); serializer.Serialize(TestFileStream, os); TestFileStream.Close(); break; } } }
private void button2_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); // Display OpenFileDialog by calling ShowDialog method Nullable<bool> result = dlg.ShowDialog(); // Get the selected file name and display in a TextBox if (result == true) { // Open document string filename = dlg.FileName; if (filename.Remove(0, filename.Length - 2) == "ac") { ObjSer os = new ObjSer(); pictureBox1.Clear(); Stream TestFileStream = File.OpenRead(filename); BinaryFormatter deserializer = new BinaryFormatter(); os = (ObjSer)deserializer.Deserialize(TestFileStream); TestFileStream.Close(); for (int i = 0; i < os.GetPicEnumerator(); i++) { pictureBox1.Add(new Image()); pictureBox1.Last().MouseLeftButtonDown += new MouseButtonEventHandler(PBFocusEvent); pictureBox1.Last().Source = StringToImage(os.GetFromPicList(i).PicArray); pictureBox1.Last().Width = StringToImage(os.GetFromPicList(i).PicArray).Width; pictureBox1.Last().Height = StringToImage(os.GetFromPicList(i).PicArray).Height; pictureBox1.Last().SetValue(DraggableExtender.CanDragProperty, true); double WidthPercent = StringToImage(os.GetFromPicList(i).PicArray).Width * zoomPercent / 100; double HeightPercent = StringToImage(os.GetFromPicList(i).PicArray).Height * zoomPercent / 100; while (pictureBox1.Last().Width > selCanv.Width || pictureBox1.Last().Height > selCanv.Height) { pictureBox1.Last().Width -= WidthPercent; pictureBox1.Last().Height -= HeightPercent; } var transform = pictureBox1.Last().RenderTransform as TranslateTransform; if (transform == null) { transform = new TranslateTransform(); pictureBox1.Last().RenderTransform = transform; } transform.X = os.GetFromPicList(i).X - Math.Abs(selCanv.Margin.Left); transform.Y = os.GetFromPicList(i).Y - Math.Abs(selCanv.Margin.Top); pictureBox1.Last().RenderTransform = transform; selCanv.Children.Add(pictureBox1.Last()); } for (int i = 0; i < os.GetTextEnumerator(); i++) { textList.Add(CreateTB()); textList.Last().Text = os.GetFromTextList(i).Text; textList.Last().FontFamily = new FontFamily(os.GetFromTextList(i).FontName); textList.Last().FontSize = os.GetFromTextList(i).FontSize; BrushConverter bc = new BrushConverter(); textList.Last().Foreground = (Brush)bc.ConvertFrom(os.GetFromTextList(i).FontColor); var transform = textList.Last().RenderTransform as TranslateTransform; if (transform == null) { transform = new TranslateTransform(); textList.Last().RenderTransform = transform; } transform.X = os.GetFromTextList(i).X - Math.Abs(selCanv.Margin.Left); transform.Y = os.GetFromTextList(i).Y - Math.Abs(selCanv.Margin.Top); textList.Last().RenderTransform = transform; selCanv.Children.Add(textList.Last()); } for (int i = 0; i < os.GetGridEnumerator(); i++) { gridList.Add(new Grid()); gridList.Last().SetValue(DraggableExtender.CanDragProperty, true); for (int f = 0; f < os.GetFromGridList(i).rows; f++) { RowDefinition row = new RowDefinition(); gridList.Last().RowDefinitions.Add(row); for (int j = 0; j < os.GetFromGridList(i).columns; j++) { ColumnDefinition column = new ColumnDefinition(); column.Width = GridLength.Auto; gridList.Last().ColumnDefinitions.Add(column); TextBox tb = CreateTableTB(); Grid.SetRow(tb, f); Grid.SetColumn(tb, j); gridList.Last().Children.Add(tb); } } int k = 0; foreach (TextBox t in gridList.Last().Children) { t.Text = os.GetFromGridList(i).text[k]; k++; } var transform = gridList.Last().RenderTransform as TranslateTransform; if (transform == null) { transform = new TranslateTransform(); gridList.Last().RenderTransform = transform; } transform.X = os.GetFromGridList(i).X - Math.Abs(selCanv.Margin.Left); transform.Y = os.GetFromGridList(i).Y - Math.Abs(selCanv.Margin.Top); gridList.Last().RenderTransform = transform; selCanv.Children.Add(gridList.Last()); } } else { pictureBox1.Add(new Image()); var uri = new Uri(filename); img = new BitmapImage(uri); pictureBox1.Last().MouseLeftButtonDown += new MouseButtonEventHandler(PBFocusEvent); pictureBox1.Last().Width = img.Width; pictureBox1.Last().Height = img.Height; pictureBox1.Last().Source = img; pictureBox1.Last().SetValue(DraggableExtender.CanDragProperty,true); double WidthPercent = img.Width * zoomPercent / 100; double HeightPercent = img.Height * zoomPercent / 100; while (pictureBox1.Last().Width > selCanv.Width || pictureBox1.Last().Height > selCanv.Height) { pictureBox1.Last().Width -= WidthPercent; pictureBox1.Last().Height -= HeightPercent; } selCanv.Children.Add(pictureBox1.Last()); } } }
private void button2_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); // Display OpenFileDialog by calling ShowDialog method Nullable <bool> result = dlg.ShowDialog(); // Get the selected file name and display in a TextBox if (result == true) { // Open document string filename = dlg.FileName; if (filename.Remove(0, filename.Length - 2) == "ac") { ObjSer os = new ObjSer(); pictureBox1.Clear(); Stream TestFileStream = File.OpenRead(filename); BinaryFormatter deserializer = new BinaryFormatter(); os = (ObjSer)deserializer.Deserialize(TestFileStream); TestFileStream.Close(); for (int i = 0; i < os.GetPicEnumerator(); i++) { pictureBox1.Add(new Image()); pictureBox1.Last().MouseLeftButtonDown += new MouseButtonEventHandler(PBFocusEvent); pictureBox1.Last().Source = StringToImage(os.GetFromPicList(i).PicArray); pictureBox1.Last().Width = StringToImage(os.GetFromPicList(i).PicArray).Width; pictureBox1.Last().Height = StringToImage(os.GetFromPicList(i).PicArray).Height; pictureBox1.Last().SetValue(DraggableExtender.CanDragProperty, true); double WidthPercent = StringToImage(os.GetFromPicList(i).PicArray).Width *zoomPercent / 100; double HeightPercent = StringToImage(os.GetFromPicList(i).PicArray).Height *zoomPercent / 100; while (pictureBox1.Last().Width > selCanv.Width || pictureBox1.Last().Height > selCanv.Height) { pictureBox1.Last().Width -= WidthPercent; pictureBox1.Last().Height -= HeightPercent; } var transform = pictureBox1.Last().RenderTransform as TranslateTransform; if (transform == null) { transform = new TranslateTransform(); pictureBox1.Last().RenderTransform = transform; } transform.X = os.GetFromPicList(i).X - Math.Abs(selCanv.Margin.Left); transform.Y = os.GetFromPicList(i).Y - Math.Abs(selCanv.Margin.Top); pictureBox1.Last().RenderTransform = transform; selCanv.Children.Add(pictureBox1.Last()); } for (int i = 0; i < os.GetTextEnumerator(); i++) { textList.Add(CreateTB()); textList.Last().Text = os.GetFromTextList(i).Text; textList.Last().FontFamily = new FontFamily(os.GetFromTextList(i).FontName); textList.Last().FontSize = os.GetFromTextList(i).FontSize; BrushConverter bc = new BrushConverter(); textList.Last().Foreground = (Brush)bc.ConvertFrom(os.GetFromTextList(i).FontColor); var transform = textList.Last().RenderTransform as TranslateTransform; if (transform == null) { transform = new TranslateTransform(); textList.Last().RenderTransform = transform; } transform.X = os.GetFromTextList(i).X - Math.Abs(selCanv.Margin.Left); transform.Y = os.GetFromTextList(i).Y - Math.Abs(selCanv.Margin.Top); textList.Last().RenderTransform = transform; selCanv.Children.Add(textList.Last()); } for (int i = 0; i < os.GetGridEnumerator(); i++) { gridList.Add(new Grid()); gridList.Last().SetValue(DraggableExtender.CanDragProperty, true); for (int f = 0; f < os.GetFromGridList(i).rows; f++) { RowDefinition row = new RowDefinition(); gridList.Last().RowDefinitions.Add(row); for (int j = 0; j < os.GetFromGridList(i).columns; j++) { ColumnDefinition column = new ColumnDefinition(); column.Width = GridLength.Auto; gridList.Last().ColumnDefinitions.Add(column); TextBox tb = CreateTableTB(); Grid.SetRow(tb, f); Grid.SetColumn(tb, j); gridList.Last().Children.Add(tb); } } int k = 0; foreach (TextBox t in gridList.Last().Children) { t.Text = os.GetFromGridList(i).text[k]; k++; } var transform = gridList.Last().RenderTransform as TranslateTransform; if (transform == null) { transform = new TranslateTransform(); gridList.Last().RenderTransform = transform; } transform.X = os.GetFromGridList(i).X - Math.Abs(selCanv.Margin.Left); transform.Y = os.GetFromGridList(i).Y - Math.Abs(selCanv.Margin.Top); gridList.Last().RenderTransform = transform; selCanv.Children.Add(gridList.Last()); } } else { pictureBox1.Add(new Image()); var uri = new Uri(filename); img = new BitmapImage(uri); pictureBox1.Last().MouseLeftButtonDown += new MouseButtonEventHandler(PBFocusEvent); pictureBox1.Last().Width = img.Width; pictureBox1.Last().Height = img.Height; pictureBox1.Last().Source = img; pictureBox1.Last().SetValue(DraggableExtender.CanDragProperty, true); double WidthPercent = img.Width * zoomPercent / 100; double HeightPercent = img.Height * zoomPercent / 100; while (pictureBox1.Last().Width > selCanv.Width || pictureBox1.Last().Height > selCanv.Height) { pictureBox1.Last().Width -= WidthPercent; pictureBox1.Last().Height -= HeightPercent; } selCanv.Children.Add(pictureBox1.Last()); } } }
private void button1_Click(object sender, RoutedEventArgs e) { selCanv.InvalidateVisual(); Microsoft.Win32.SaveFileDialog savedialog = new Microsoft.Win32.SaveFileDialog(); savedialog.Title = "Сохранить картинку как ..."; savedialog.OverwritePrompt = true; savedialog.CheckPathExists = true; savedialog.Filter = "AC File(*.ac)|*.ac|" + "Bitmap File(*.bmp)|*.bmp|" + "GIF File(*.gif)|*.gif|" + "JPEG File(*.jpg)|*.jpg|" + "TIF File(*.tif)|*.tif|" + "PNG File(*.png)|*.png"; if (savedialog.ShowDialog() == true) { string fileName = savedialog.FileName; string strFilExtn = fileName.Remove(0, fileName.Length - 3); // Save file switch (strFilExtn) { case "bmp": CreateSaveBitmap(selCanv, fileName); break; case "jpg": CreateSaveBitmap(selCanv, fileName); break; case "gif": CreateSaveBitmap(selCanv, fileName); break; case "tif": CreateSaveBitmap(selCanv, fileName); break; case "png": CreateSaveBitmap(selCanv, fileName); break; case ".ac": ObjSer os = new ObjSer(); foreach (Image pic in pictureBox1) { Point relativePoint = pic.TransformToAncestor(this).Transform(new Point(0, 0)); SerPic sp = new SerPic(relativePoint.X, relativePoint.Y, pic.Width, pic.Height, ImageToString(pic.Source)); os.AddToPicList(sp); } foreach (TextBox text in textList) { Point relativePoint = text.TransformToAncestor(this).Transform(new Point(0, 0)); SerText st = new SerText(relativePoint.X, relativePoint.Y, text.FontFamily.Source, text.FontSize, text.Foreground.ToString(), text.Text); os.AddToTextList(st); } foreach (Grid table in gridList) { List<string> text = new List<string>(); foreach (TextBox t in table.Children) { text.Add(t.Text); } Point relativePoint = table.TransformToAncestor(this).Transform(new Point(0, 0)); SerGrid sg = new SerGrid(relativePoint.X, relativePoint.Y, table.RowDefinitions.Count, table.ColumnDefinitions.Count / table.RowDefinitions.Count, text); os.AddToGridList(sg); } Stream TestFileStream = File.Create(fileName); BinaryFormatter serializer = new BinaryFormatter(); serializer.Serialize(TestFileStream, os); TestFileStream.Close(); break; } } }