Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10. using System.Drawing.Imaging;
  11. using System.IO;
  12. using FIP;
  13.  
  14. namespace Rysowanie
  15. {
  16. public partial class Form1 : Form
  17. {
  18. FIP.FIP fip;
  19. Graphics grafika;
  20. Bitmap img;
  21. Pen p = new Pen(Color.Black, 1);
  22. Point sp = new Point(0, 0);
  23. Point ep = new Point(0, 0);
  24. Color color;
  25. int obrazek;
  26. int i;
  27. private int cX, cY, x, y, dX, dY;
  28. public Form1()
  29. {
  30. InitializeComponent();
  31. color = Color.Black;
  32. }
  33. void Form1MouseUp(object sender, MouseEventArgs e)
  34. {
  35.  
  36. }
  37. private void nowyToolStripMenuItem_Click(object sender, EventArgs e)
  38. {
  39. rysowanie.Refresh();
  40. rysowanie.Image = null;
  41. groupBox1.Enabled = true;
  42. groupBox2.Enabled = true;
  43. groupBox3.Enabled = true;
  44. groupBox4.Enabled = true;
  45. }
  46.  
  47. private void wczytajPlikToolStripMenuItem_Click(object sender, EventArgs e)
  48. {
  49. fip = new FIP.FIP();
  50. OpenFileDialog obraz = new OpenFileDialog();
  51. obraz.Filter = "Png files|*.png|jpeg files|*jpg|bitmaps|*.bmp";
  52. if (obraz.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  53. {
  54. rysowanie.Image = Image.FromFile(obraz.FileName);
  55.  
  56. }
  57.  
  58. img = new Bitmap(rysowanie.Image);
  59. }
  60.  
  61. private void zapiszToolStripMenuItem_Click(object sender, EventArgs e)
  62. {
  63. Bitmap bmp = new Bitmap(rysowanie.Width, rysowanie.Height);
  64. Graphics g = Graphics.FromImage(bmp);
  65. Rectangle rect = rysowanie.RectangleToScreen(rysowanie.ClientRectangle);
  66. g.CopyFromScreen(rect.Location, Point.Empty, rysowanie.Size);
  67. g.Dispose();
  68. SaveFileDialog save = new SaveFileDialog();
  69. save.Filter = "Png files|*.png|jpeg files|*jpg|bitmaps|*.bmp";
  70. if (save.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  71. {
  72. if (File.Exists(save.FileName))
  73. {
  74. File.Delete(save.FileName);
  75. }
  76. if (save.FileName.Contains(".jpg"))
  77. {
  78. bmp.Save(save.FileName, ImageFormat.Jpeg);
  79. }
  80. else if (save.FileName.Contains(".png"))
  81. {
  82. bmp.Save(save.FileName, ImageFormat.Png);
  83. }
  84. else if (save.FileName.Contains(".bmp"))
  85. {
  86. bmp.Save(save.FileName, ImageFormat.Bmp);
  87. }
  88. }
  89. }
  90.  
  91. private void zamknijToolStripMenuItem_Click(object sender, EventArgs e)
  92. {
  93. Application.Exit();
  94. }
  95.  
  96. private void buttonczarny_Click(object sender, EventArgs e)
  97. {
  98. color = Color.Black;
  99. wybrany.BackColor = color;
  100. toolStripStatusLabel3.Text = "Kolor: Czarny";
  101. }
  102.  
  103. private void buttonbialy_Click(object sender, EventArgs e)
  104. {
  105. color = Color.White;
  106. wybrany.BackColor = color;
  107. toolStripStatusLabel3.Text = "Kolor: Biały";
  108. }
  109.  
  110. private void buttonszary_Click(object sender, EventArgs e)
  111. {
  112. color = Color.Gray;
  113. wybrany.BackColor = color;
  114. toolStripStatusLabel3.Text = "Kolor: Szary";
  115. }
  116.  
  117. private void buttonfioletowy_Click(object sender, EventArgs e)
  118. {
  119. color = Color.Purple;
  120. wybrany.BackColor = color;
  121. toolStripStatusLabel3.Text = "Kolor: Fioletowy";
  122. }
  123.  
  124. private void buttonniebieski_Click(object sender, EventArgs e)
  125. {
  126. color = Color.Blue;
  127. wybrany.BackColor = color;
  128. toolStripStatusLabel3.Text = "Kolor: Niebieski";
  129. }
  130.  
  131. private void buttonaqua_Click(object sender, EventArgs e)
  132. {
  133. color = Color.Aqua;
  134. wybrany.BackColor = color;
  135. toolStripStatusLabel3.Text = "Kolor: Aqua";
  136. }
  137.  
  138. private void buttonCzerwony_Click(object sender, EventArgs e)
  139. {
  140. color = Color.Red;
  141. wybrany.BackColor = color;
  142. toolStripStatusLabel3.Text = "Kolor: Czerwony";
  143. }
  144.  
  145. private void buttonturkusowy_Click(object sender, EventArgs e)
  146. {
  147. color = Color.Turquoise;
  148. wybrany.BackColor = color;
  149. toolStripStatusLabel3.Text = "Kolor: Turkusowy";
  150. }
  151.  
  152. private void buttonzolty_Click(object sender, EventArgs e)
  153. {
  154. color = Color.Yellow;
  155. wybrany.BackColor = color;
  156. toolStripStatusLabel3.Text = "Kolor: Żółty";
  157. }
  158.  
  159. private void Form1_Load(object sender, EventArgs e)
  160. {
  161. grafika = rysowanie.CreateGraphics();
  162. }
  163.  
  164. private void buttonpomaranczowy_Click(object sender, EventArgs e)
  165. {
  166. color = Color.Orange;
  167. wybrany.BackColor = color;
  168. toolStripStatusLabel3.Text = "Kolor: Pomarańczowy";
  169. }
  170.  
  171. private void buttonrozowy_Click(object sender, EventArgs e)
  172. {
  173. color = Color.Pink;
  174. wybrany.BackColor = color;
  175. toolStripStatusLabel3.Text = "Kolor: Różowy";
  176. }
  177.  
  178. private void buttonolowek_Click(object sender, EventArgs e)
  179. {
  180. obrazek = 1;
  181. toolStripStatusLabel1.Text = "Narzędzie: Ołówek";
  182. toolStripStatusLabel2.Text = "";
  183. groupBox1.Enabled = true;
  184. groupBox4.Enabled = false;
  185. }
  186.  
  187. private void buttongumka_Click(object sender, EventArgs e)
  188. {
  189. obrazek = 2;
  190. color = Color.White;
  191. toolStripStatusLabel1.Text = "Narzędzie: Gumka";
  192. toolStripStatusLabel3.Text = "";
  193. groupBox1.Enabled = false;
  194. }
  195.  
  196. private void groupBox4_Enter(object sender, EventArgs e)
  197. {
  198. groupBox1.Enabled = true;
  199. }
  200.  
  201. private void buttonnajmniejszy_Click(object sender, EventArgs e)
  202. {
  203. obrazek = 7;
  204. toolStripStatusLabel2.Text = "Rozmiar: Najmniejszy";
  205. }
  206.  
  207. private void buttonmaly_Click(object sender, EventArgs e)
  208. {
  209. obrazek = 8;
  210. toolStripStatusLabel2.Text = "Rozmiar: Mały";
  211. }
  212.  
  213. private void buttonsredni_Click(object sender, EventArgs e)
  214. {
  215. obrazek = 9;
  216. toolStripStatusLabel2.Text = "Rozmiar: Średni";
  217. }
  218.  
  219. private void buttonduzy_Click(object sender, EventArgs e)
  220. {
  221. obrazek = 10;
  222. toolStripStatusLabel2.Text = "Rozmiar: Duży";
  223.  
  224. }
  225.  
  226. private void buttonpedzel_Click(object sender, EventArgs e)
  227. {
  228. obrazek = 6;
  229. toolStripStatusLabel1.Text = "Narzędzie: Pędzel";
  230. groupBox1.Enabled = true;
  231. groupBox4.Enabled = true;
  232. }
  233.  
  234. private void buttonprosta_Click(object sender, EventArgs e)
  235. {
  236. obrazek = 3;
  237. toolStripStatusLabel1.Text = "Rysuje: Linie Prostą";
  238. }
  239.  
  240. private void buttonkolo_Click(object sender, EventArgs e)
  241. {
  242. obrazek = 4;
  243. toolStripStatusLabel1.Text = "Rysuje: Koło";
  244. }
  245.  
  246. private void buttonkwadrat_Click(object sender, EventArgs e)
  247. {
  248. obrazek = 5;
  249. toolStripStatusLabel1.Text = "Rysuje: Kwadrat";
  250. }
  251.  
  252. private void wyczyśćToolStripMenuItem_Click(object sender, EventArgs e)
  253. {
  254. rysowanie.Refresh();
  255. rysowanie.Image = null;
  256. groupBox1.Enabled = true;
  257. groupBox2.Enabled = true;
  258. groupBox3.Enabled = true;
  259. groupBox4.Enabled = true;
  260. }
  261. private void Form1_Paint(object sender, PaintEventArgs e)
  262. {
  263.  
  264. }
  265.  
  266. private void buttonbezier_Click(object sender, EventArgs e)
  267. {
  268. obrazek = 11;
  269. toolStripStatusLabel1.Text = "Rysuje: Krzywą Beziera";
  270. }
  271.  
  272. private void groupBox5_Enter(object sender, EventArgs e)
  273. {
  274. groupBox4.Enabled=false;
  275. groupBox1.Enabled = true;
  276. toolStripStatusLabel2.Text = "";
  277. }
  278.  
  279. private void groupBox2_Enter(object sender, EventArgs e)
  280. {
  281. groupBox4.Enabled = true;
  282.  
  283. }
  284.  
  285. private void buttonwycinek_Click(object sender, EventArgs e)
  286. {
  287. obrazek = 12;
  288. toolStripStatusLabel1.Text = "Rysuje: Wycinek";
  289. }
  290.  
  291. private void button1_Click(object sender, EventArgs e)
  292. {
  293. Bitmap negatyw = fip.NegativeImageColor(img);
  294. rysowanie.Image = negatyw;
  295. }
  296.  
  297. private void buttonczarnobialy_Click(object sender, EventArgs e)
  298. {
  299. Bitmap czarnobialy = fip.ToBlackwhite(img,5);
  300. rysowanie.Image = czarnobialy;
  301. }
  302.  
  303. private void buttonzielony_Click(object sender, EventArgs e)
  304. {
  305. color = Color.Green;
  306. wybrany.BackColor = color;
  307. toolStripStatusLabel3.Text = "Kolor: Zielony";
  308. }
  309. void rysowanieMouseMove(object sender, MouseEventArgs e)
  310. {
  311. labelx.Text = " " + Convert.ToString(x);
  312. labely.Text = " " + Convert.ToString(y);
  313. if (i == 1)
  314. {
  315. ep = e.Location;
  316. x = e.X;
  317. y = e.Y;
  318.  
  319. if (obrazek == 1)
  320. {
  321. grafika.DrawLine(new Pen(color), sp, ep);
  322. }
  323. else if (obrazek == 2)
  324. {
  325. grafika.FillEllipse(new SolidBrush(color), e.X, e.Y, 60, 60);
  326. }
  327. else if (obrazek == 6)
  328. {
  329. grafika.FillEllipse(new SolidBrush(color), e.X, e.Y, 60, 60);
  330. }
  331. else if (obrazek == 7)
  332. {
  333. grafika.FillEllipse(new SolidBrush(color), e.X, e.Y, 5, 5);
  334. }
  335. else if (obrazek == 8)
  336. {
  337. grafika.FillEllipse(new SolidBrush(color), e.X, e.Y, 15, 15);
  338. }
  339. else if (obrazek == 9)
  340. {
  341. grafika.FillEllipse(new SolidBrush(color), e.X, e.Y, 25, 25);
  342. }
  343. else if (obrazek == 10)
  344. {
  345. grafika.FillEllipse(new SolidBrush(color), e.X, e.Y, 35, 35);
  346. }
  347. else if (obrazek == 11)
  348. {
  349. grafika.DrawBezier(new Pen(color), e.X, e.Y, 100, 250, 100, 200, 150, 30);
  350. }
  351. else if (obrazek == 12)
  352. {
  353. grafika.DrawPie(new Pen(color), e.X, e.Y, 50, 100, 150, 250);
  354. }
  355.  
  356. sp = ep;
  357. }
  358.  
  359. }
  360. void rysowanieMouseDown(object sender, MouseEventArgs e)
  361. {
  362.  
  363. sp = e.Location;
  364. if (e.Button == MouseButtons.Left)
  365. {
  366. i = 1;
  367. }
  368. cX = e.X;
  369. cY = e.Y;
  370. }
  371. void rysowanieMouseUp(object sender, MouseEventArgs e)
  372. {
  373. i = 0;
  374. }
  375. void rysowanieMouseClick(object sender, MouseEventArgs e)
  376. {
  377. if (i == 1)
  378. {
  379. x = e.X;
  380. y = e.Y;
  381. dX = e.X - cX;
  382. dY = e.Y - cY;
  383. if (obrazek == 3)
  384. {
  385. grafika.DrawLine(new Pen(color), cX, cY, e.X, e.Y);
  386. }
  387. if (obrazek == 4)
  388. {
  389. grafika.DrawEllipse(new Pen(color), cX, cY, dX, dY);
  390. }
  391. if (obrazek == 5)
  392. {
  393. grafika.DrawRectangle(new Pen(color), cX, cY, dX, dY);
  394. }
  395.  
  396. }
  397. }
  398. }
  399. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement