Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.Drawing.Imaging;
- using System.IO;
- using FIP;
- namespace Rysowanie
- {
- public partial class Form1 : Form
- {
- FIP.FIP fip;
- Graphics grafika;
- Bitmap img;
- Pen p = new Pen(Color.Black, 1);
- Point sp = new Point(0, 0);
- Point ep = new Point(0, 0);
- Color color;
- int obrazek;
- int i;
- private int cX, cY, x, y, dX, dY;
- public Form1()
- {
- InitializeComponent();
- color = Color.Black;
- }
- void Form1MouseUp(object sender, MouseEventArgs e)
- {
- }
- private void nowyToolStripMenuItem_Click(object sender, EventArgs e)
- {
- rysowanie.Refresh();
- rysowanie.Image = null;
- groupBox1.Enabled = true;
- groupBox2.Enabled = true;
- groupBox3.Enabled = true;
- groupBox4.Enabled = true;
- }
- private void wczytajPlikToolStripMenuItem_Click(object sender, EventArgs e)
- {
- fip = new FIP.FIP();
- OpenFileDialog obraz = new OpenFileDialog();
- obraz.Filter = "Png files|*.png|jpeg files|*jpg|bitmaps|*.bmp";
- if (obraz.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- rysowanie.Image = Image.FromFile(obraz.FileName);
- }
- img = new Bitmap(rysowanie.Image);
- }
- private void zapiszToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Bitmap bmp = new Bitmap(rysowanie.Width, rysowanie.Height);
- Graphics g = Graphics.FromImage(bmp);
- Rectangle rect = rysowanie.RectangleToScreen(rysowanie.ClientRectangle);
- g.CopyFromScreen(rect.Location, Point.Empty, rysowanie.Size);
- g.Dispose();
- SaveFileDialog save = new SaveFileDialog();
- save.Filter = "Png files|*.png|jpeg files|*jpg|bitmaps|*.bmp";
- if (save.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- if (File.Exists(save.FileName))
- {
- File.Delete(save.FileName);
- }
- if (save.FileName.Contains(".jpg"))
- {
- bmp.Save(save.FileName, ImageFormat.Jpeg);
- }
- else if (save.FileName.Contains(".png"))
- {
- bmp.Save(save.FileName, ImageFormat.Png);
- }
- else if (save.FileName.Contains(".bmp"))
- {
- bmp.Save(save.FileName, ImageFormat.Bmp);
- }
- }
- }
- private void zamknijToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void buttonczarny_Click(object sender, EventArgs e)
- {
- color = Color.Black;
- wybrany.BackColor = color;
- toolStripStatusLabel3.Text = "Kolor: Czarny";
- }
- private void buttonbialy_Click(object sender, EventArgs e)
- {
- color = Color.White;
- wybrany.BackColor = color;
- toolStripStatusLabel3.Text = "Kolor: Biały";
- }
- private void buttonszary_Click(object sender, EventArgs e)
- {
- color = Color.Gray;
- wybrany.BackColor = color;
- toolStripStatusLabel3.Text = "Kolor: Szary";
- }
- private void buttonfioletowy_Click(object sender, EventArgs e)
- {
- color = Color.Purple;
- wybrany.BackColor = color;
- toolStripStatusLabel3.Text = "Kolor: Fioletowy";
- }
- private void buttonniebieski_Click(object sender, EventArgs e)
- {
- color = Color.Blue;
- wybrany.BackColor = color;
- toolStripStatusLabel3.Text = "Kolor: Niebieski";
- }
- private void buttonaqua_Click(object sender, EventArgs e)
- {
- color = Color.Aqua;
- wybrany.BackColor = color;
- toolStripStatusLabel3.Text = "Kolor: Aqua";
- }
- private void buttonCzerwony_Click(object sender, EventArgs e)
- {
- color = Color.Red;
- wybrany.BackColor = color;
- toolStripStatusLabel3.Text = "Kolor: Czerwony";
- }
- private void buttonturkusowy_Click(object sender, EventArgs e)
- {
- color = Color.Turquoise;
- wybrany.BackColor = color;
- toolStripStatusLabel3.Text = "Kolor: Turkusowy";
- }
- private void buttonzolty_Click(object sender, EventArgs e)
- {
- color = Color.Yellow;
- wybrany.BackColor = color;
- toolStripStatusLabel3.Text = "Kolor: Żółty";
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- grafika = rysowanie.CreateGraphics();
- }
- private void buttonpomaranczowy_Click(object sender, EventArgs e)
- {
- color = Color.Orange;
- wybrany.BackColor = color;
- toolStripStatusLabel3.Text = "Kolor: Pomarańczowy";
- }
- private void buttonrozowy_Click(object sender, EventArgs e)
- {
- color = Color.Pink;
- wybrany.BackColor = color;
- toolStripStatusLabel3.Text = "Kolor: Różowy";
- }
- private void buttonolowek_Click(object sender, EventArgs e)
- {
- obrazek = 1;
- toolStripStatusLabel1.Text = "Narzędzie: Ołówek";
- toolStripStatusLabel2.Text = "";
- groupBox1.Enabled = true;
- groupBox4.Enabled = false;
- }
- private void buttongumka_Click(object sender, EventArgs e)
- {
- obrazek = 2;
- color = Color.White;
- toolStripStatusLabel1.Text = "Narzędzie: Gumka";
- toolStripStatusLabel3.Text = "";
- groupBox1.Enabled = false;
- }
- private void groupBox4_Enter(object sender, EventArgs e)
- {
- groupBox1.Enabled = true;
- }
- private void buttonnajmniejszy_Click(object sender, EventArgs e)
- {
- obrazek = 7;
- toolStripStatusLabel2.Text = "Rozmiar: Najmniejszy";
- }
- private void buttonmaly_Click(object sender, EventArgs e)
- {
- obrazek = 8;
- toolStripStatusLabel2.Text = "Rozmiar: Mały";
- }
- private void buttonsredni_Click(object sender, EventArgs e)
- {
- obrazek = 9;
- toolStripStatusLabel2.Text = "Rozmiar: Średni";
- }
- private void buttonduzy_Click(object sender, EventArgs e)
- {
- obrazek = 10;
- toolStripStatusLabel2.Text = "Rozmiar: Duży";
- }
- private void buttonpedzel_Click(object sender, EventArgs e)
- {
- obrazek = 6;
- toolStripStatusLabel1.Text = "Narzędzie: Pędzel";
- groupBox1.Enabled = true;
- groupBox4.Enabled = true;
- }
- private void buttonprosta_Click(object sender, EventArgs e)
- {
- obrazek = 3;
- toolStripStatusLabel1.Text = "Rysuje: Linie Prostą";
- }
- private void buttonkolo_Click(object sender, EventArgs e)
- {
- obrazek = 4;
- toolStripStatusLabel1.Text = "Rysuje: Koło";
- }
- private void buttonkwadrat_Click(object sender, EventArgs e)
- {
- obrazek = 5;
- toolStripStatusLabel1.Text = "Rysuje: Kwadrat";
- }
- private void wyczyśćToolStripMenuItem_Click(object sender, EventArgs e)
- {
- rysowanie.Refresh();
- rysowanie.Image = null;
- groupBox1.Enabled = true;
- groupBox2.Enabled = true;
- groupBox3.Enabled = true;
- groupBox4.Enabled = true;
- }
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- }
- private void buttonbezier_Click(object sender, EventArgs e)
- {
- obrazek = 11;
- toolStripStatusLabel1.Text = "Rysuje: Krzywą Beziera";
- }
- private void groupBox5_Enter(object sender, EventArgs e)
- {
- groupBox4.Enabled=false;
- groupBox1.Enabled = true;
- toolStripStatusLabel2.Text = "";
- }
- private void groupBox2_Enter(object sender, EventArgs e)
- {
- groupBox4.Enabled = true;
- }
- private void buttonwycinek_Click(object sender, EventArgs e)
- {
- obrazek = 12;
- toolStripStatusLabel1.Text = "Rysuje: Wycinek";
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Bitmap negatyw = fip.NegativeImageColor(img);
- rysowanie.Image = negatyw;
- }
- private void buttonczarnobialy_Click(object sender, EventArgs e)
- {
- Bitmap czarnobialy = fip.ToBlackwhite(img,5);
- rysowanie.Image = czarnobialy;
- }
- private void buttonzielony_Click(object sender, EventArgs e)
- {
- color = Color.Green;
- wybrany.BackColor = color;
- toolStripStatusLabel3.Text = "Kolor: Zielony";
- }
- void rysowanieMouseMove(object sender, MouseEventArgs e)
- {
- labelx.Text = " " + Convert.ToString(x);
- labely.Text = " " + Convert.ToString(y);
- if (i == 1)
- {
- ep = e.Location;
- x = e.X;
- y = e.Y;
- if (obrazek == 1)
- {
- grafika.DrawLine(new Pen(color), sp, ep);
- }
- else if (obrazek == 2)
- {
- grafika.FillEllipse(new SolidBrush(color), e.X, e.Y, 60, 60);
- }
- else if (obrazek == 6)
- {
- grafika.FillEllipse(new SolidBrush(color), e.X, e.Y, 60, 60);
- }
- else if (obrazek == 7)
- {
- grafika.FillEllipse(new SolidBrush(color), e.X, e.Y, 5, 5);
- }
- else if (obrazek == 8)
- {
- grafika.FillEllipse(new SolidBrush(color), e.X, e.Y, 15, 15);
- }
- else if (obrazek == 9)
- {
- grafika.FillEllipse(new SolidBrush(color), e.X, e.Y, 25, 25);
- }
- else if (obrazek == 10)
- {
- grafika.FillEllipse(new SolidBrush(color), e.X, e.Y, 35, 35);
- }
- else if (obrazek == 11)
- {
- grafika.DrawBezier(new Pen(color), e.X, e.Y, 100, 250, 100, 200, 150, 30);
- }
- else if (obrazek == 12)
- {
- grafika.DrawPie(new Pen(color), e.X, e.Y, 50, 100, 150, 250);
- }
- sp = ep;
- }
- }
- void rysowanieMouseDown(object sender, MouseEventArgs e)
- {
- sp = e.Location;
- if (e.Button == MouseButtons.Left)
- {
- i = 1;
- }
- cX = e.X;
- cY = e.Y;
- }
- void rysowanieMouseUp(object sender, MouseEventArgs e)
- {
- i = 0;
- }
- void rysowanieMouseClick(object sender, MouseEventArgs e)
- {
- if (i == 1)
- {
- x = e.X;
- y = e.Y;
- dX = e.X - cX;
- dY = e.Y - cY;
- if (obrazek == 3)
- {
- grafika.DrawLine(new Pen(color), cX, cY, e.X, e.Y);
- }
- if (obrazek == 4)
- {
- grafika.DrawEllipse(new Pen(color), cX, cY, dX, dY);
- }
- if (obrazek == 5)
- {
- grafika.DrawRectangle(new Pen(color), cX, cY, dX, dY);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement