Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //XAML
- <ComboBox x:Name="cboBrushSize" HorizontalAlignment="Left" Margin="568,195,0,0" VerticalAlignment="Top" Width="120" SelectionChanged="ComboBox_SelectionChanged">
- <ComboBoxItem>1</ComboBoxItem>
- <ComboBoxItem IsSelected="True">2</ComboBoxItem>
- <ComboBoxItem>4</ComboBoxItem>
- <ComboBoxItem>6</ComboBoxItem>
- <ComboBoxItem>8</ComboBoxItem>
- <ComboBoxItem>10</ComboBoxItem>
- </ComboBox>
- //---------------------------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.IO;
- using Microsoft.Win32;
- using System.Windows.Forms;
- using System.Windows.Media.Animation;
- namespace AndrzejIwaniuk
- {
- /// <summary>
- /// Eksport obrazka do formatu JPEG
- /// Zmiana kolorów linii
- /// Prosta animacja
- /// </summary>
- public partial class MainWindow : Window
- {
- string nazwaPliku = "";
- static System.Windows.Media.Color col;
- //static System.Drawing.Color col;
- public MainWindow()
- {
- InitializeComponent();
- }
- private void btnCzysc_Click(object sender, RoutedEventArgs e)
- {
- //czyść obszar pisania
- recznePisanie.Strokes.Clear();
- }
- //zapisz obrazek jako plik JPG
- public void EskportDoJPEG(InkCanvas obszar)
- {
- double
- x1 = obszar.Margin.Left,
- x2 = obszar.Margin.Top,
- x3 = obszar.Margin.Right,
- x4 = obszar.Margin.Bottom;
- obszar.Margin = new Thickness(0, 0, 0, 0);
- Size size = new Size(obszar.Width, obszar.Height);
- obszar.Measure(size);
- obszar.Arrange(new Rect(size));
- RenderTargetBitmap renderBitmap =
- new RenderTargetBitmap(
- (int)size.Width,
- (int)size.Height,
- 96,
- 96,
- PixelFormats.Default);
- renderBitmap.Render(obszar);
- otworzOknoDialogoZapisz();
- try
- {
- using (FileStream fs = File.Open(nazwaPliku, FileMode.Create))
- {
- JpegBitmapEncoder encoder = new JpegBitmapEncoder();
- encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
- encoder.Save(fs);
- }
- }
- catch (Exception e)
- {
- }
- obszar.Margin = new Thickness(x1, x2, x3, x4);
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- EskportDoJPEG(recznePisanie);
- }
- void otworzOknoDialogoZapisz()
- {
- //otworz save dialog box
- // konfiguracja okna dialogowego Zapisu
- Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
- dlg.FileName = "nazwa_pliku"; // domyślna nazwa pliku
- dlg.DefaultExt = ".jpg"; // domyśle rozszerzenie pliku
- dlg.Filter = "Obrazek (.jpg)|*.jpg"; // pokauj tylko pliku *.jpg
- // Pokaz okno dialogowe Zapisu
- Nullable<bool> result = dlg.ShowDialog();
- // Sprawdź zmienna result z okna Dialogowe Zapis
- if (result == true)
- {
- // Zapisanie dokumentu
- nazwaPliku = dlg.FileName;
- }
- //------
- }
- private void koloDialog()
- //private System.Windows.Media.Color koloDialog()
- {
- ColorDialog colorDialog =
- new ColorDialog();
- colorDialog.AllowFullOpen = true;
- colorDialog.ShowDialog();
- //col = colorDialog.Color;
- col.A = colorDialog.Color.A;
- col.B = colorDialog.Color.B;
- col.G = colorDialog.Color.G;
- col.R = colorDialog.Color.R;
- }
- private void btnKolory_Click(object sender, RoutedEventArgs e)
- {
- koloDialog();
- ChangeColor(recznePisanie, col);
- }
- void ChangeColor(InkCanvas inkCanvas, System.Windows.Media.Color color)
- //void ChangeColor(InkCanvas inkCanvas, Color color)
- {
- //foreach (var stroke in inkCanvas.Strokes)
- //{
- //stroke.DrawingAttributes.Color = Colors.Aqua;// col;
- inkCanvas.DefaultDrawingAttributes.Color = Color.FromArgb(col.A, col.R, col.G, col.B);
- //stroke.DrawingAttributes.Color = Color.FromArgb(col.A,col.R,col.G,col.B);
- //}
- }
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- DoubleAnimation da = new DoubleAnimation
- (360, 0, new Duration(TimeSpan.FromSeconds(3)));
- RotateTransform rt = new RotateTransform();
- image1.RenderTransform = rt;
- image1.RenderTransformOrigin = new Point(0.5, 0.5);
- da.RepeatBehavior = RepeatBehavior.Forever;
- rt.BeginAnimation(RotateTransform.AngleProperty, da);
- }
- private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (cboBrushSize.Items.Count > 0 && ((ComboBoxItem)cboBrushSize.SelectedItem).Content != null)
- {
- /// Sets the brush size.
- recznePisanie.DefaultDrawingAttributes.Width = Convert.ToDouble(((ComboBoxItem)cboBrushSize.SelectedItem).Content);
- recznePisanie.DefaultDrawingAttributes.Height = Convert.ToDouble(((ComboBoxItem)cboBrushSize.SelectedItem).Content);
- }
- }
- private void image1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- recznePisanie.Background = Brushes.DarkSlateBlue;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement