ImageEditorUserControl.cs

Description du code

ImageEditorUserControl.cs est un fichier du projet PhotoBrol.
Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/photobrol/.

Projet PhotoBrol :

Editeur d'images en CSharp.

Code source ou contenu du fichier

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using be.gaudry.photobrol.view.dialogs;
  9. using be.gaudry.view.dialogs;
  10. using be.gaudry.photobrol.model.filters;
  11. using System.IO;
  12. using System.Drawing.Imaging;
  13. using be.gaudry.model.drawing;
  14. using be.gaudry.model;
  15. using be.gaudry.model.config;
  16.  
  17. namespace be.gaudry.photobrol.view.controls
  18. {
  19. public partial class ImageEditorUserControl : UserControl
  20. {
  21.  
  22. #region constructor and declarations
  23. private BrolImage img, curImg;
  24. private History<BrolImage> imageHistory;
  25. private TrackIntParameterDialog trkIntDialog;
  26. private TrackFloatParameterDialog trkFloatDialog;
  27. private ImageFormat[] validImagesFormats;
  28.  
  29.  
  30. public ImageEditorUserControl()
  31. {
  32. img = new BrolImage();
  33. curImg = new BrolImage();
  34. imageHistory = new History<BrolImage>();
  35. trkIntDialog = new TrackIntParameterDialog();
  36. trkFloatDialog = new TrackFloatParameterDialog();
  37. validImagesFormats = new ImageFormat[]{ ImageFormat.Jpeg, ImageFormat.Bmp };
  38. InitializeComponent();
  39. openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
  40. openFileDialog.Filter = "Fichiers Jpeg (*.jpg;*.jpeg)|*.jpg;*.jpeg|Fichiers bitmap (*.bmp)|*bmp|Tous les fichiers valides (*.jpg;*.jpeg;*.bmp)|*.jpg;*.jpeg;*.bmp";
  41. saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
  42. // saveFileDialog.Filter items MUST MATCHES validImagesFormats items order !!!
  43. saveFileDialog.Filter = "Fichiers Jpeg (*.jpg;*.jpeg)|*.jpg;*.jpeg|Fichiers bitmap (*.bmp)|*bmp";
  44. foreach(String sizeMode in Enum.GetNames(typeof(Wallpaper.Affichage)))
  45. {
  46. destopImgSizeModeCB.Items.Add(sizeMode);
  47. }
  48. if(destopImgSizeModeCB.Items.Count>0)
  49. destopImgSizeModeCB.SelectedIndex = 0;
  50.  
  51. checkActions();
  52.  
  53.  
  54. SourcesManager.addSource(new Source(
  55. "Histograms",
  56. this.Name,
  57. "http://www.codeproject.com/cs/miscctrl/histogramcontrol.asp",
  58. "Informations sur l'utilisation des histogrammes"
  59. )
  60. );
  61. SourcesManager.addSource(new Source(
  62. "EXIFextractor",
  63. this.Name,
  64. "http://www.codeproject.com/csharp/exifextractor.asp",
  65. "Extraction des informations EXIF des images"
  66. )
  67. );
  68. SourcesManager.addSource(new Source(
  69. "Professional C#",
  70. this.Name,
  71. "http://www.codeproject.com/books/1861004990.asp",
  72. "Traitement GDI+"
  73. )
  74. );
  75. SourcesManager.addSource(new Source(
  76. "ColorAvgLum selection",
  77. this.Name,
  78. "http://www.codeproject.com/cs/miscctrl/ColorPaletteControl.asp",
  79. "Création de palettes de couleurs"
  80. )
  81. );
  82. }
  83. #endregion
  84.  
  85. #region properties
  86.  
  87. /// <summary>
  88. /// Path of the start image
  89. /// </summary>
  90. [
  91. Category("Image Editor options"),
  92. Description("Path of the start image")
  93. ]
  94. public String ImageLocation
  95. {
  96. get
  97. {
  98. return img.FullPath;
  99. }
  100. set
  101. {
  102. if (value != null)
  103. {
  104. if (img == null)
  105. img = new BrolImage(value);
  106. else
  107. img.FullPath = value;
  108. initImage();
  109. }
  110. }
  111. }
  112.  
  113. /// <summary>
  114. /// Image to edit
  115. /// </summary>
  116. [
  117. Category("Image Editor options"),
  118. Description("Image")
  119. ]
  120. public Image Image
  121. {
  122. get
  123. {
  124. return scrollPBUC.Bitmap;
  125. }
  126. set
  127. {
  128. if (img == null)
  129. img = new BrolImage();
  130. if (value != null)
  131. {
  132. img.Image = new Bitmap(value);
  133. initImage();
  134. }
  135. }
  136. }
  137.  
  138.  
  139. /// <summary>
  140. /// Image with informations
  141. /// </summary>
  142. [
  143. Category("Image Editor options"),
  144. Description("Image with informations")
  145. ]
  146. public BrolImage BrolImage
  147. {
  148. get { return img; }
  149. set
  150. {
  151. if (value!=null)
  152. {
  153. if (value.Deep == 24)
  154. {
  155. img = value;
  156. initImage();
  157. }
  158. else if (value.Deep != 0)
  159. {
  160. MessageBox.Show(
  161. this,
  162. String.Format("L'éditeur ne traite pas actuellement les images codées en {0} bits",value.Deep),
  163. "Erreur de chargement",
  164. MessageBoxButtons.OK,
  165. MessageBoxIcon.Information
  166. );
  167. }
  168. }
  169. }
  170. }
  171. #endregion
  172.  
  173. #region public methods
  174. public void setMenuStripDock(DockStyle dockStyle)
  175. {
  176. this.mainMenuStrip.Dock = dockStyle;
  177. }
  178. public void undo()
  179. {
  180. try
  181. {
  182. curImg = imageHistory.Undo;
  183. setHistoryDisplay();
  184. scrollPBUC.Bitmap = curImg.Image;
  185. }
  186. catch (InvalidOperationException) { }
  187. }
  188. public void redo()
  189. {
  190. try
  191. {
  192. curImg = imageHistory.Redo;
  193. setHistoryDisplay();
  194. scrollPBUC.Bitmap = curImg.Image;
  195. }
  196. catch (InvalidOperationException) { }
  197. }
  198.  
  199. #endregion
  200.  
  201. #region private image methods
  202.  
  203. private void initImage()
  204. {
  205. if (img != null && curImg != null && img.Image!=null)
  206. {
  207. enableImgSettings(false);
  208. curImg.Image = img.Image;
  209. imagePG.SelectedObject = img;
  210. curImagePG.SelectedObject = curImg;
  211. imageHistory.clear();
  212. imageHistory.go(curImg);
  213. scrollPBUC.Bitmap = curImg.Image;
  214. enableImgSettings(true);
  215. }
  216. checkActions();
  217. setHistoryDisplay();
  218. }
  219. private void setHistoryDisplay()
  220. {
  221. int undoCount = imageHistory.UndoCount;
  222. int redoCount = imageHistory.RedoCount;
  223. undoTSB.Enabled = (undoCount > 1);//the first item is set on load image
  224. annulerToolStripMenuItem.Enabled = undoTSB.Enabled;
  225. redoTSB.Enabled = (redoCount > 0);
  226. rétablirToolStripMenuItem.Enabled = redoTSB.Enabled;
  227. historyLbl.Text = String.Format("Opération {0}/{1}", undoCount, undoCount+redoCount);
  228. }
  229. private void setThumb()
  230. {
  231. imageHistory.go(curImg);
  232. setHistoryDisplay();
  233. //scrollPBUC.Bitmap.Dispose();
  234. scrollPBUC.Bitmap = curImg.Image;
  235. }
  236. private void checkActions()
  237. {
  238. bool basicFilterEnabled = ImageHelper.isImg(img.FullPath);
  239. foreach(ToolStripItem tsi in imageTsMi.DropDownItems)
  240. {
  241. tsi.Enabled = basicFilterEnabled;
  242. }
  243. ouvrirToolStripMenuItem.Enabled = true;
  244.  
  245. filterTsMi.Enabled = basicFilterEnabled;
  246. foreach(ToolStripItem tsi in toolStrip1.Items)
  247. {
  248. tsi.Enabled = basicFilterEnabled;
  249. }
  250. openTSB.Enabled = true;
  251. mruTsSB.Enabled = mruTsSB.DropDownItems.Count>0;
  252. collapseTabsTSB.Enabled = true;
  253.  
  254. saveAsTSMenuItem.Enabled = true;
  255.  
  256. thumbCMS.Enabled = basicFilterEnabled;
  257. splitContainer1.Enabled = basicFilterEnabled;
  258. }
  259. private void scrollPBUC_EnabledChanged(object sender, EventArgs e)
  260. {
  261. if (scrollPBUC.Enabled)
  262. rgblHistogramUserControl1.GatherStatistics(scrollPBUC.Bitmap);
  263. //histogramUserControl1.GatherStatistics(scrollPBUC.Bitmap);
  264. }
  265. #endregion
  266.  
  267. #region image filters groupbox
  268. private void invertAction(object sender, EventArgs e)
  269. {
  270.  
  271. enableImgSettings(false);
  272. if (BitmapFilter.Invert(curImg.Image))
  273. {
  274. setThumb();
  275. }
  276. enableImgSettings(true);
  277. }
  278.  
  279. private void grayScaleAction(object sender, EventArgs e)
  280. {
  281.  
  282. enableImgSettings(false);
  283. if (BitmapFilter.GrayScale(curImg.Image))
  284. {
  285. setThumb();
  286. }
  287. enableImgSettings(true);
  288. }
  289. #endregion
  290.  
  291. #region image settings tp
  292. private void enableImgSettings(bool enable)
  293. {
  294. /*scrollPBUC.Enabled = enable;
  295.   foreach (Control c in settingsTP.Controls)
  296.   {
  297.   c.Enabled = enable;
  298.   }*/
  299. try
  300. {
  301. splitContainer1.Enabled = enable;
  302. this.Cursor = (enable)?Cursors.Default:Cursors.WaitCursor;
  303. }
  304. catch(ArgumentException)
  305. {
  306. System.Threading.Thread.Sleep(0);
  307. enableImgSettings(enable);
  308. }
  309. }
  310. private void editImageBtn_Click(object sender, EventArgs e)
  311. {
  312. Bitmap bmp = (Bitmap)img.Image.Clone();
  313. if (bmp == null)
  314. return;
  315. enableImgSettings(false);
  316.  
  317. if (!BitmapFilter.Brightness(bmp, brightnessTrkB.Value))
  318. {
  319. enableImgSettings(true);
  320. bmp.Dispose();
  321. return;
  322. }
  323.  
  324. if (!BitmapFilter.Contrast(bmp, (sbyte)contrastTrkB.Value))
  325. {
  326. enableImgSettings(true);
  327. bmp.Dispose();
  328. return;
  329. }
  330.  
  331. double red = (double)gamaRedTrkB.Value / 100;
  332. double green = (double)gamaGreenTrkB.Value / 100;
  333. double blue = (double)gamaBlueTrkB.Value / 100;
  334. if (BitmapFilter.Gamma(bmp, red,green,blue))
  335. {
  336. curImg.Image.Dispose();
  337. curImg.Image = (Bitmap)bmp.Clone();
  338. setThumb();
  339. }
  340. bmp.Dispose();
  341. enableImgSettings(true);
  342. }
  343.  
  344.  
  345.  
  346. private void brightnessTrkB_Scroll(object sender, EventArgs e)
  347. {
  348. brightnessTB.Text = brightnessTrkB.Value.ToString();
  349. }
  350.  
  351. private void brightnessTB_TextChanged(object sender, EventArgs e)
  352. {
  353. setTrkValues(brightnessTrkB, brightnessTB);
  354. }
  355.  
  356. private void contrastTrkB_Scroll(object sender, EventArgs e)
  357. {
  358. contrastTB.Text = contrastTrkB.Value.ToString();
  359. }
  360.  
  361. private void contrastTB_TextChanged(object sender, EventArgs e)
  362. {
  363. setTrkValues(contrastTrkB, contrastTB);
  364. }
  365.  
  366. private void gamaRedTrkB_Scroll(object sender, EventArgs e)
  367. {
  368. gamaRedTB.Text = gamaRedTrkB.Value.ToString();
  369. }
  370. private void gamaRedTB_TextChanged(object sender, EventArgs e)
  371. {
  372. setTrkValues(gamaRedTrkB, gamaRedTB);
  373. }
  374. private void gamaGreenTrkB_Scroll(object sender, EventArgs e)
  375. {
  376. gamaGreenTB.Text = gamaGreenTrkB.Value.ToString();
  377. }
  378.  
  379. private void gamaGreenTB_TextChanged(object sender, EventArgs e)
  380. {
  381. setTrkValues(gamaGreenTrkB, gamaGreenTB);
  382. }
  383.  
  384. private void gamaBlueTrkB_Scroll(object sender, EventArgs e)
  385. {
  386. gamaBlueTB.Text = gamaBlueTrkB.Value.ToString();
  387. }
  388.  
  389. private void gamaBlueTB_TextChanged(object sender, EventArgs e)
  390. {
  391. setTrkValues(gamaBlueTrkB, gamaBlueTB);
  392. }
  393.  
  394. private void setTrkValues(TrackBar trkB, TextBox tB)
  395. {
  396. int i;
  397. if (Int32.TryParse(tB.Text, out i) && i > trkB.Minimum && i < trkB.Maximum)
  398. {
  399. trkB.Value = i;
  400. }
  401. else
  402. {
  403. tB.Text = trkB.Value.ToString();
  404. }
  405. }
  406.  
  407. #endregion
  408.  
  409. #region flip and rotations
  410.  
  411. private void rotate90hTSB_Click(object sender, EventArgs e)
  412. {
  413. curImg.Image.RotateFlip(RotateFlipType.Rotate90FlipNone);
  414. setThumb();
  415. }
  416.  
  417. private void rotate90ahTSB_Click(object sender, EventArgs e)
  418. {
  419. curImg.Image.RotateFlip(RotateFlipType.Rotate270FlipNone);
  420. setThumb();
  421. }
  422.  
  423. private void flipxTSB_Click(object sender, EventArgs e)
  424. {
  425. curImg.Image.RotateFlip(RotateFlipType.RotateNoneFlipX);
  426. setThumb();
  427. }
  428.  
  429. private void flipyTSB_Click(object sender, EventArgs e)
  430. {
  431. curImg.Image.RotateFlip(RotateFlipType.RotateNoneFlipY);
  432. setThumb();
  433. }
  434. #endregion
  435.  
  436. #region desktop
  437. private void desktopColorBtn_Click(object sender, EventArgs e)
  438. {
  439. if (DialogResult.OK.Equals(colorDialog1.ShowDialog()))
  440. {
  441. desktopColorPanel.BackColor = colorDialog1.Color;
  442. }
  443. }
  444.  
  445. private void wallpaperBtn_Click(object sender, EventArgs e)
  446. {
  447. Wallpaper wallpaper = new Wallpaper(
  448. img.FullPath,
  449. (Wallpaper.Affichage)Enum.Parse(typeof(Wallpaper.Affichage), destopImgSizeModeCB.SelectedItem.ToString()),
  450. desktopColorPanel.BackColor
  451. );
  452. if (wallpaper.Afficher())
  453. {
  454. MessageBox.Show(
  455. this,
  456. "Modifications effectuées.",
  457. "Configuration du bureau",
  458. MessageBoxButtons.OK,
  459. MessageBoxIcon.Information
  460. );
  461. }
  462. else
  463. {
  464. MessageBox.Show(
  465. this,
  466. "Une erreur s'est produite lors de l'affichage du Wallpaper",
  467. "Configuration du bureau",
  468. MessageBoxButtons.OK,
  469. MessageBoxIcon.Error
  470. );
  471. }
  472. }
  473. #endregion
  474.  
  475. #region zoom options
  476. private void zoomPosCmsMi_Click(object sender, EventArgs e)
  477. {
  478. scrollPBUC.zoomIn();
  479. }
  480.  
  481. private void zoomNegCmsMi_Click(object sender, EventArgs e)
  482. {
  483. scrollPBUC.zoomOut();
  484. }
  485.  
  486. private void zoomFitCmsMi_Click(object sender, EventArgs e)
  487. {
  488. scrollPBUC.zoomToFit();
  489. }
  490.  
  491. private void zoom100CmsMi_Click(object sender, EventArgs e)
  492. {
  493. scrollPBUC.zoomToRealSize();
  494. }
  495. #endregion
  496.  
  497. #region filters menu
  498. private void gaussianBlurTsMi_Click(object sender, EventArgs e)
  499. {
  500.  
  501. enableImgSettings(false);
  502. trkIntDialog.Text = "Atténuation : Flou gaussien";
  503. trkIntDialog.Info = "Effet de flou gaussien";
  504. trkIntDialog.ValueInfo = "Angle : ";
  505. trkIntDialog.MinimumValue = 1;
  506. trkIntDialog.MaximumValue = 10;
  507. trkIntDialog.Value = 5;
  508. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  509. {
  510. if (BitmapFilter.GaussianBlur(curImg.Image, trkIntDialog.Value))
  511. {
  512. setLastAction(gaussianBlurTsMi, new EventHandler(gaussianBlurTsMi_Click));
  513. setThumb();
  514. }
  515. }
  516. enableImgSettings(true);
  517. }
  518.  
  519. private void moreBlurTsMi_Click(object sender, EventArgs e)
  520. {
  521.  
  522. enableImgSettings(false);
  523. trkIntDialog.Text = "Atténuation : Flou";
  524. trkIntDialog.Info = "Effet de flou";
  525. trkIntDialog.ValueInfo = "Valeur : ";
  526. trkIntDialog.MinimumValue = 1;
  527. trkIntDialog.MaximumValue = 5;
  528. trkIntDialog.Value = 1;
  529. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  530. {
  531. if (BitmapFilter.Smooth(curImg.Image, trkIntDialog.Value))
  532. {
  533. setThumb();
  534. }
  535. }
  536. enableImgSettings(true);
  537. }
  538.  
  539. private void brightnessTsMi_Click(object sender, EventArgs e)
  540. {
  541.  
  542. enableImgSettings(false);
  543. trkIntDialog.Text = "Luminosité";
  544. trkIntDialog.Info = "Réglage de la luminosité";
  545. trkIntDialog.ValueInfo = "Valeur : ";
  546. trkIntDialog.MinimumValue = -100;
  547. trkIntDialog.MaximumValue = 100;
  548. trkIntDialog.Value = 0;
  549. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  550. {
  551. if (BitmapFilter.Brightness(curImg.Image, trkIntDialog.Value))
  552. {
  553. setThumb();
  554. }
  555. }
  556. enableImgSettings(true);
  557. }
  558.  
  559. private void contrastTsMi_Click(object sender, EventArgs e)
  560. {
  561.  
  562.  
  563. enableImgSettings(false);
  564. trkIntDialog.Text = "Constraste";
  565. trkIntDialog.Info = "Réglage du contraste";
  566. trkIntDialog.ValueInfo = "Valeur : ";
  567. trkIntDialog.MinimumValue = -100;
  568. trkIntDialog.MaximumValue = 100;
  569. trkIntDialog.Value = 0;
  570. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  571. {
  572. if (BitmapFilter.Contrast(curImg.Image, (sbyte)trkIntDialog.Value))
  573. {
  574. setThumb();
  575. }
  576. }
  577. enableImgSettings(true);
  578. }
  579.  
  580. private void meanRemovalTsMi_Click(object sender, EventArgs e)
  581. {
  582.  
  583. enableImgSettings(false);
  584. trkIntDialog.Text = "Renforcement : Accentuation";
  585. trkIntDialog.Info = "Filtre d'accentuation";
  586. trkIntDialog.ValueInfo = "Accentué de : ";
  587. trkIntDialog.MinimumValue = 1;
  588. trkIntDialog.MaximumValue = 10;
  589. trkIntDialog.Value = 1;
  590. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  591. {
  592. if (BitmapFilter.MeanRemoval(curImg.Image, trkIntDialog.Value))
  593. {
  594. setThumb();
  595. }
  596. }
  597. enableImgSettings(true);
  598. }
  599.  
  600. private void sharpenMore2TsMi_Click(object sender, EventArgs e)
  601. {
  602.  
  603. enableImgSettings(false);
  604. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  605. {
  606. if (BitmapFilter.MeanRemoval(curImg.Image, 9))
  607. {
  608. setThumb();
  609. }
  610. }
  611. enableImgSettings(true);
  612. }
  613.  
  614. private void sharpenPTsMi_Click(object sender, EventArgs e)
  615. {
  616.  
  617. enableImgSettings(false);
  618. trkIntDialog.Text = "Renforcement : Netteté optimisée";
  619. trkIntDialog.Info = "Filtre de netteté optimisée";
  620. trkIntDialog.ValueInfo = "Valeur : ";
  621. trkIntDialog.MinimumValue = 0;
  622. trkIntDialog.MaximumValue = 20;
  623. trkIntDialog.Value = 9;
  624. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  625. {
  626. if (BitmapFilter.MeanRemoval(curImg.Image, trkIntDialog.Value))
  627. {
  628. setThumb();
  629. }
  630. }
  631. enableImgSettings(true);
  632. }
  633.  
  634. private void sharpenMoreTsMi_Click(object sender, EventArgs e)
  635. {
  636.  
  637. enableImgSettings(false);
  638. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  639. {
  640. if (BitmapFilter.MeanRemoval(curImg.Image, 7))
  641. {
  642. setThumb();
  643. }
  644. }
  645. enableImgSettings(true);
  646. }
  647.  
  648. private void embossTsMi_Click(object sender, EventArgs e)
  649. {
  650.  
  651. enableImgSettings(false);
  652. if (BitmapFilter.EmbossLaplacian(curImg.Image))
  653. {
  654. setThumb();
  655. }
  656. enableImgSettings(true);
  657. }
  658.  
  659. private void edgeTsMi_Click(object sender, EventArgs e)
  660. {
  661.  
  662. enableImgSettings(false);
  663. trkIntDialog.Text = "Esquisse : chrome";
  664. trkIntDialog.Info = "Effet chrome";
  665. trkIntDialog.ValueInfo = "Valeur : ";
  666. trkIntDialog.MinimumValue = 0;
  667. trkIntDialog.MaximumValue = 20;
  668. trkIntDialog.Value = 9;
  669. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  670. {
  671. if (BitmapFilter.EdgeEnhance(curImg.Image, (byte)trkIntDialog.Value))
  672. {
  673. setThumb();
  674. }
  675. }
  676. enableImgSettings(true);
  677. }
  678.  
  679. private void edgeInvertTsMi_Click(object sender, EventArgs e)
  680. {
  681.  
  682. enableImgSettings(false);
  683. trkIntDialog.Text = "Esquisse : crayon";
  684. trkIntDialog.Info = "Effet crayon";
  685. trkIntDialog.ValueInfo = "Valeur : ";
  686. trkIntDialog.MinimumValue = 1;
  687. trkIntDialog.MaximumValue = 10;
  688. trkIntDialog.Value = 5;
  689. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  690. {
  691. if (BitmapFilter.EdgeDetectConvolution(curImg.Image, BitmapFilter.EDGE_DETECT_SOBEL, (byte)trkIntDialog.Value))
  692. {
  693. if (BitmapFilter.Invert(curImg.Image))
  694. {
  695. setThumb();
  696. }
  697. }
  698. }
  699. enableImgSettings(true);
  700. }
  701.  
  702. private void kirshTsMi_Click(object sender, EventArgs e)
  703. {
  704.  
  705. enableImgSettings(false);
  706. trkIntDialog.Text = "Esquisse : tampon";
  707. trkIntDialog.Info = "Effet tampon";
  708. trkIntDialog.ValueInfo = "Valeur : ";
  709. trkIntDialog.MinimumValue = 0;
  710. trkIntDialog.MaximumValue = 10;
  711. trkIntDialog.Value = 5;
  712. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  713. {
  714. if (BitmapFilter.EdgeDetectConvolution(curImg.Image, BitmapFilter.EDGE_DETECT_KIRSH, (byte)trkIntDialog.Value))
  715. {
  716. setThumb();
  717. }
  718. }
  719. enableImgSettings(true);
  720. }
  721.  
  722. private void prewittInvertTsMi_Click(object sender, EventArgs e)
  723. {
  724.  
  725. enableImgSettings(false);
  726. trkIntDialog.Text = "Esquisse : fusain";
  727. trkIntDialog.Info = "Effet fusain";
  728. trkIntDialog.ValueInfo = "Valeur : ";
  729. trkIntDialog.MinimumValue = 0;
  730. trkIntDialog.MaximumValue = 10;
  731. trkIntDialog.Value = 1;
  732. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  733. {
  734. if (BitmapFilter.EdgeDetectConvolution(curImg.Image, BitmapFilter.EDGE_DETECT_PREWITT, (byte)trkIntDialog.Value))
  735. {
  736. if (BitmapFilter.Invert(curImg.Image))
  737. {
  738. setThumb();
  739. }
  740. }
  741. }
  742. enableImgSettings(true);
  743. }
  744.  
  745. private void edgeVInvertTsMi_Click(object sender, EventArgs e)
  746. {
  747.  
  748. enableImgSettings(false);
  749. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  750. {
  751. if (BitmapFilter.EdgeDetectVertical(curImg.Image))
  752. {
  753. if (BitmapFilter.Invert(curImg.Image))
  754. {
  755. setThumb();
  756. }
  757. }
  758. }
  759. enableImgSettings(true);
  760. }
  761.  
  762. private void edgeHInvertTsMi_Click(object sender, EventArgs e)
  763. {
  764.  
  765. enableImgSettings(false);
  766. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  767. {
  768. if (BitmapFilter.EdgeDetectHorizontal(curImg.Image))
  769. {
  770. if (BitmapFilter.Invert(curImg.Image))
  771. {
  772. setThumb();
  773. }
  774. }
  775. }
  776. enableImgSettings(true);
  777. }
  778.  
  779. private void edgeEnhanceTsMi_Click(object sender, EventArgs e)
  780. {
  781.  
  782. enableImgSettings(false);
  783. if (BitmapFilter.EdgeEnhance(curImg.Image, (byte)10))
  784. {
  785. setThumb();
  786. }
  787. enableImgSettings(true);
  788. }
  789.  
  790. private void resizeImageTsMi_Click(object sender, EventArgs e)
  791. {
  792.  
  793. enableImgSettings(false);
  794. ResizeDialog rd = new ResizeDialog();
  795. rd.ParamWidth = curImg.Image.Width;
  796. rd.ParamHeight = curImg.Image.Height;
  797. if (rd.ShowDialog(this) == DialogResult.OK)
  798. {
  799. curImg.Image = BitmapFilter.Resize(
  800. curImg.Image,
  801. rd.ParamWidth,
  802. rd.ParamHeight,
  803. rd.ParamBilinear
  804. );
  805. setThumb();
  806. }
  807. enableImgSettings(true);
  808. }
  809.  
  810. private void jitterTsMi_Click(object sender, EventArgs e)
  811. {
  812.  
  813. enableImgSettings(false);
  814. trkIntDialog.Text = "Texture : grain";
  815. trkIntDialog.Info = "Effet grain";
  816. trkIntDialog.ValueInfo = "Intensité : ";
  817. trkIntDialog.MinimumValue = 0;
  818. trkIntDialog.MaximumValue = 20;
  819. trkIntDialog.Value = 5;
  820. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  821. {
  822. if (BitmapFilter.RandomJitter(curImg.Image, (short)trkIntDialog.Value))
  823. {
  824. setThumb();
  825. }
  826. }
  827. enableImgSettings(true);
  828. }
  829.  
  830. private void swirlTsMi_Click(object sender, EventArgs e)
  831. {
  832.  
  833. enableImgSettings(false);
  834. trkFloatDialog.Text = "Déformation : spirale";
  835. trkFloatDialog.Info = "Effet spirale";
  836. trkFloatDialog.ValueInfo = "Angle : ";
  837. trkFloatDialog.MinimumValue = 0F;
  838. trkFloatDialog.MaximumValue = 0.9F;
  839. trkFloatDialog.Value = 0.4F;
  840. trkFloatDialog.ValueChkBText = "Antialiasing";
  841. trkFloatDialog.DisplayChkB = true;
  842. if (trkFloatDialog.ShowDialog(this) == DialogResult.OK)
  843. {
  844. if (BitmapFilter.Swirl(curImg.Image, trkFloatDialog.Value, trkFloatDialog.ValueChkBChecked))
  845. {
  846. setThumb();
  847. }
  848. }
  849. enableImgSettings(true);
  850. }
  851.  
  852. private void sphereTsMi_Click(object sender, EventArgs e)
  853. {
  854.  
  855. enableImgSettings(false);
  856. trkIntDialog.Text = "Déformation : sphère";
  857. trkIntDialog.Info = "Effet sphère";
  858. trkIntDialog.ValueInfo = "Déplacement : ";
  859. trkIntDialog.MinimumValue = 0;
  860. trkIntDialog.MaximumValue = 50;
  861. trkIntDialog.Value = 0;
  862. trkIntDialog.ValueChkB2Text = "Horizontal";
  863. trkIntDialog.DisplayChkB2 = true;
  864. trkIntDialog.ValueChkB1Text = "Vertical";
  865. trkIntDialog.DisplayChkB1 = true;
  866. trkIntDialog.ValueChkB3Text = "Antialiasing";
  867. trkIntDialog.DisplayChkB3 = true;
  868. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  869. {
  870. int vVal = (trkIntDialog.ValueChkB1Checked) ? trkIntDialog.Value : 0;
  871. int hVal = (trkIntDialog.ValueChkB2Checked) ? trkIntDialog.Value : 0;
  872. if (BitmapFilter.Sphere(curImg.Image, trkIntDialog.ValueChkB3Checked, vVal, hVal))
  873. {
  874. setThumb();
  875. }
  876. }
  877. enableImgSettings(true);
  878. }
  879.  
  880. private void sphereNegTsMi_Click(object sender, EventArgs e)
  881. {
  882.  
  883. enableImgSettings(false);
  884. trkIntDialog.Text = "Déformation : grand angle";
  885. trkIntDialog.Info = "Effet grand angle";
  886. trkIntDialog.ValueInfo = "Déplacement : ";
  887. trkIntDialog.MinimumValue = 0;
  888. trkIntDialog.MaximumValue = 50;
  889. trkIntDialog.Value = 0;
  890. trkIntDialog.ValueChkB1Text = "Antialiasing";
  891. trkIntDialog.DisplayChkB1 = true;
  892. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  893. {
  894. if (BitmapFilter.Sphere(curImg.Image, trkIntDialog.ValueChkB1Checked, trkIntDialog.Value + 40, 0 - (trkIntDialog.Value + 40)))
  895. {
  896. setThumb();
  897. }
  898. }
  899. enableImgSettings(true);
  900. }
  901.  
  902. private void TimeWarpTsMi_Click(object sender, EventArgs e)
  903. {
  904.  
  905. enableImgSettings(false);
  906. trkIntDialog.Text = "Déformation : contraction";
  907. trkIntDialog.Info = "Effet contraction";
  908. trkIntDialog.ValueInfo = "Déplacement : ";
  909. trkIntDialog.MinimumValue = 0;
  910. trkIntDialog.MaximumValue = 25;
  911. trkIntDialog.Value = 15;
  912. trkIntDialog.ValueChkB1Text = "Antialiasing";
  913. trkIntDialog.DisplayChkB1 = true;
  914. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  915. {
  916. if (BitmapFilter.TimeWarp(curImg.Image, (byte)trkIntDialog.Value, trkIntDialog.ValueChkB1Checked))
  917. {
  918. setThumb();
  919. }
  920. }
  921. enableImgSettings(true);
  922. }
  923.  
  924. private void waterTsMi_Click(object sender, EventArgs e)
  925. {
  926.  
  927. enableImgSettings(false);
  928. trkIntDialog.Text = "Déformation : onde";
  929. trkIntDialog.Info = "Effet d'onde";
  930. trkIntDialog.ValueInfo = "Amplitude : ";
  931. trkIntDialog.MinimumValue = 0;
  932. trkIntDialog.MaximumValue = 25;
  933. trkIntDialog.Value = 15;
  934. trkIntDialog.ValueChkB1Text = "Antialiasing";
  935. trkIntDialog.DisplayChkB1 = true;
  936. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  937. {
  938. if (BitmapFilter.Water(curImg.Image, (short)trkIntDialog.Value, trkIntDialog.ValueChkB1Checked))
  939. {
  940. setThumb();
  941. }
  942. }
  943. enableImgSettings(true);
  944. }
  945.  
  946. private void pixMosaicTsMi_Click(object sender, EventArgs e)
  947. {
  948.  
  949. enableImgSettings(false);
  950. trkIntDialog.Text = "Pixellisation : mosaïque";
  951. trkIntDialog.Info = "Effet mosaïque";
  952. trkIntDialog.ValueInfo = "Carreaux : ";
  953. trkIntDialog.MinimumValue = 1;
  954. trkIntDialog.MaximumValue = 30;
  955. trkIntDialog.Value = 15;
  956. trkIntDialog.ValueChkB1Text = "Contours";
  957. trkIntDialog.DisplayChkB1 = true;
  958. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  959. {
  960. if (BitmapFilter.Pixelate(curImg.Image, (short)trkIntDialog.Value, trkIntDialog.ValueChkB1Checked))
  961. {
  962. setThumb();
  963. }
  964. }
  965. enableImgSettings(true);
  966. }
  967.  
  968. private void sepiaTsMi_Click(object sender, EventArgs e)
  969. {
  970. enableImgSettings(false);
  971. Color color = Color.FromArgb(0, 0, 0, 0);
  972. HSLDialog hslDi = new HSLDialog();
  973. hslDi.SelectedColor = color;
  974. if (hslDi.ShowDialog() == DialogResult.OK)
  975. {
  976. color = hslDi.SelectedColor;
  977. if (BitmapFilter.sepia(curImg.Image, color.R / 2, color.G / 2, color.B / 2))
  978. if (BitmapFilter.GaussianBlur(curImg.Image, 4))
  979. {
  980. setLastAction(sepiaTsMi, new EventHandler(sepiaTsMi_Click));
  981. setThumb();
  982. }
  983. }
  984. enableImgSettings(true);
  985. }
  986.  
  987. private void s2ToolStripMenuItem_Click(object sender, EventArgs e)
  988. {
  989.  
  990. enableImgSettings(false);
  991. trkIntDialog.Text = "Artistique : sépia";
  992. trkIntDialog.Info = "Effet sépia";
  993. trkIntDialog.ValueInfo = "Rouge : ";
  994. trkIntDialog.MinimumValue = 0;
  995. trkIntDialog.MaximumValue = 255;
  996. trkIntDialog.Value = 0;
  997. trkIntDialog.ValueChkB1Text = "V";
  998. trkIntDialog.ValueChkB2Text = "R";
  999. trkIntDialog.ValueChkB3Text = "B";
  1000. trkIntDialog.DisplayChkB1 = true;
  1001. trkIntDialog.DisplayChkB2 = true;
  1002. trkIntDialog.DisplayChkB3 = true;
  1003. int r, v, b;
  1004. v = (trkIntDialog.ValueChkB1Checked) ? trkIntDialog.Value : 0;
  1005. r = (trkIntDialog.ValueChkB2Checked) ? trkIntDialog.Value : 0;
  1006. b = (trkIntDialog.ValueChkB3Checked) ? trkIntDialog.Value : 0;
  1007. if (trkIntDialog.ShowDialog(this) == DialogResult.OK)
  1008. {
  1009. if (BitmapFilter.sepia(curImg.Image, r, v, b))
  1010. {
  1011. if (BitmapFilter.GaussianBlur(curImg.Image, 4))
  1012. setThumb();
  1013. }
  1014. }
  1015. enableImgSettings(true);
  1016. }
  1017.  
  1018. private void colorAvgLumTsMi_Click(object sender, EventArgs e)
  1019. {
  1020.  
  1021. enableImgSettings(false);
  1022. Color color = Color.FromArgb(0, 0, 0);
  1023. HSLDialog hslDi = new HSLDialog();
  1024. if (hslDi.ShowDialog() == DialogResult.OK)
  1025. {
  1026. color = hslDi.SelectedColor;
  1027. if (BitmapFilter.ColorAvgLum(curImg.Image, color.R / 2, color.G / 2, color.B / 2))
  1028. setThumb();
  1029. }
  1030. enableImgSettings(true);
  1031. }
  1032.  
  1033. private void colorFastTsMi_Click(object sender, EventArgs e)
  1034. {
  1035.  
  1036. enableImgSettings(false);
  1037. Color color = Color.FromArgb(0, 0, 0);
  1038. HSLDialog hslDi = new HSLDialog();
  1039. if (hslDi.ShowDialog() == DialogResult.OK)
  1040. {
  1041. color = hslDi.SelectedColor;
  1042. if (BitmapFilter.colorFast(curImg.Image, color.R / 2, color.G / 2, color.B / 2))
  1043. setThumb();
  1044. }
  1045. enableImgSettings(true);
  1046. }
  1047. #endregion
  1048.  
  1049. private void aboutPhotoBrolTsMi_Click(object sender, EventArgs e)
  1050. {
  1051. new AboutPhotobrolDialog().ShowDialog(this);
  1052. }
  1053.  
  1054. private void openTSMenuItem_Click(object sender, EventArgs e)
  1055. {
  1056. if (DialogResult.OK == openFileDialog.ShowDialog())
  1057. {
  1058. if (ImageHelper.isImg(openFileDialog.FileName))
  1059. {
  1060. ToolStripMenuItem tsmi = new ToolStripMenuItem(Path.GetFileNameWithoutExtension(openFileDialog.FileName));
  1061. if (!mruTsSB.DropDownItems.Contains(tsmi))
  1062. {
  1063. mruTsSB.DropDownItems.Add(tsmi);
  1064. tsmi.ToolTipText = openFileDialog.FileName;
  1065. tsmi.Image = iconList1.getImage(openFileDialog.FileName);
  1066. tsmi.Click += new EventHandler(openMruTsMi_Click);
  1067. }
  1068. ImageLocation = openFileDialog.FileName;
  1069. saveFileDialog.InitialDirectory = Path.GetDirectoryName(openFileDialog.FileName);
  1070. }
  1071. else
  1072. {
  1073. if (MessageBox.Show(
  1074. this,
  1075. "Les fichiers {0} ne sont pas pris en charge par PhotoBrol",
  1076. "Erreur de chargement",
  1077. MessageBoxButtons.RetryCancel,
  1078. MessageBoxIcon.Stop
  1079. ) == DialogResult.Retry)
  1080. {
  1081. openTSMenuItem_Click(sender, e);
  1082. }
  1083. }
  1084. }
  1085. }
  1086. private void openMruTsMi_Click(object sender, EventArgs e)
  1087. {
  1088. ToolStripMenuItem tsmi = sender as ToolStripMenuItem;
  1089. if (tsmi != null)
  1090. {
  1091. ImageLocation = tsmi.ToolTipText;
  1092. }
  1093. }
  1094.  
  1095. private void reloadImgTsMi_Click(object sender, EventArgs e)
  1096. {
  1097. ImageLocation = img.FullPath;
  1098. }
  1099.  
  1100. private void collapseTabsTSB_Click(object sender, EventArgs e)
  1101. {
  1102. splitContainer1.Panel2Collapsed = !splitContainer1.Panel2Collapsed;
  1103. }
  1104.  
  1105. private void annulerToolStripMenuItem_Click(object sender, EventArgs e)
  1106. {
  1107. undo();
  1108. }
  1109.  
  1110. private void rétablirToolStripMenuItem_Click(object sender, EventArgs e)
  1111. {
  1112. redo();
  1113. }
  1114.  
  1115. private void saveTsMi_Click(object sender, EventArgs e)
  1116. {
  1117. if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
  1118. {
  1119. //String ext = Path.GetExtension(saveFileDialog.FileName).ToUpper();
  1120. String ext = validImagesFormats[saveFileDialog.FilterIndex-1].ToString().ToLower();
  1121. String outputName = saveFileDialog.FileName;
  1122. if (!outputName.EndsWith("." + ext))
  1123. outputName += "." + ext;
  1124. img.Image = curImg.Image;
  1125. switch (ext)
  1126. {
  1127. case "jpeg":
  1128. case "jpg":
  1129. SaveImageDialog sid = new SaveImageDialog();
  1130. //sid.InputImage = curImg.Image;
  1131. sid.setImageToCompress(img);
  1132. sid.ImagePath = outputName;
  1133. if (sid.ShowDialog(this) == DialogResult.OK)
  1134. {
  1135. //sid.InputImage.Save(outputName, ImageFormat.Jpeg);
  1136. sid.saveImageCompressed();
  1137. }
  1138. break;
  1139. /*case "bmp":
  1140.   curImg.Image.Save(outputName, ImageFormat.Bmp);
  1141.   break;*/
  1142. default:
  1143. /*MessageBox.Show(
  1144.   this,
  1145.   String.Format("Format d'image non supporté : {0}",ext),
  1146.   "Erreur",
  1147.   MessageBoxButtons.OK,
  1148.   MessageBoxIcon.Stop
  1149.   );*/
  1150. curImg.Image.Save(outputName, validImagesFormats[saveFileDialog.FilterIndex - 1]);
  1151. break;
  1152. }
  1153. }
  1154. }
  1155.  
  1156. private void mruToolStripMenuItem_Click(object sender, EventArgs e)
  1157. {
  1158.  
  1159. }
  1160. /*
  1161.   private void button1_Click(object sender, EventArgs e)
  1162.   {
  1163.   if(curImg.Image!=null)
  1164.   setBrolChart(Imager2.ImagerBitmap.getGreyscaleHistogram(curImg.Image));
  1165.   }
  1166.   public void setBrolChart(Stat stat)
  1167.   {
  1168.   Color[] colors = new Color[stat.Values.Length];
  1169.   Color color;
  1170.   float[] displacements = new float[stat.Values.Length];
  1171.  
  1172.   chartCtl.Values = stat.Values;
  1173.   chartCtl.Texts = stat.Texts;
  1174.   chartCtl.ToolTips = stat.Labels;
  1175.  
  1176.   for (int i = 0; i < stat.Values.Length; i++)
  1177.   {
  1178.   color = BrolColor.getBrolColor(i).BackColor;
  1179.   colors[i] = color;
  1180.   displacements[i] = 0F;
  1181.   }
  1182.  
  1183.   chartCtl.Colors = colors;
  1184.   chartCtl.SliceRelativeDisplacements = displacements;
  1185.   }*/
  1186.  
  1187. private void setLastAction(ToolStripMenuItem tsMi, EventHandler e)
  1188. {
  1189. int index = toolStrip1.Items.IndexOf(lastActionTSB);
  1190. lastActionTSB = new ToolStripButton(tsMi.Text);
  1191. if (tsMi.Image != null)
  1192. {
  1193. lastActionTSB.Image = tsMi.Image;
  1194. }
  1195. lastActionTSB.Click += e;
  1196. toolStrip1.Items.Insert(index, lastActionTSB);
  1197. lastActionTSB.Visible = true;
  1198.  
  1199. lastActionTsMi = tsMi;
  1200. filterTsMi.DropDownItems.Insert(0,lastActionTsMi);
  1201. lastActionTsMi.Visible = true;
  1202. lastActionTsS.Visible = true;
  1203. }
  1204.  
  1205. private void showColorsTsMi_Click(object sender, EventArgs e)
  1206. {
  1207. KnownColorsDialog form = new KnownColorsDialog();
  1208. form.Show(this);
  1209. }
  1210. }
  1211. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/photobrol/view/controls/ 
IcôneNomTailleModification
IcôneNomTailleModification
| _ Répertoire parent0 octets1715898510 17/05/2024 00:28:30
| _histogram0 octets1541007196 31/10/2018 18:33:16
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/photobrol/view/controls/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csRGBLHistogramUserControl.cs7.13 Ko31/10/2018 18:32:52-refusé-
Afficher le fichier .cs|.csHistogramUserControl.Designer.cs15.78 Ko31/10/2018 18:32:52-refusé-
Afficher le fichier .cs|.csCompressJpegUserControl.Designer.cs13.8 Ko31/10/2018 18:32:51-refusé-
Afficher le fichier .resx|.resxCompressJpegUserControl.resx5.68 Ko31/10/2018 18:32:52-refusé-
Afficher le fichier .resx|.resxRGBLHistogramUserControl.resx5.68 Ko31/10/2018 18:32:52-refusé-
Afficher le fichier .cs|.csHistogramUserControl.cs6.31 Ko31/10/2018 18:32:52-refusé-
Afficher le fichier .resx|.resxHistogramUserControl.resx5.68 Ko31/10/2018 18:32:52-refusé-
Afficher le fichier .cs|.csCompressJpegUserControl.cs3.77 Ko31/10/2018 18:32:51-refusé-
Afficher le fichier .cs|.csRGBLHistogramUserControl.Designer.cs29.94 Ko31/10/2018 18:32:52-refusé-
Afficher le fichier .cs|.csImageEditorUserControl.cs41.8 Ko31/10/2018 18:32:52-refusé-
Afficher le fichier .resx|.resxImageEditorUserControl.resx17.34 Ko31/10/2018 18:32:52-refusé-
Afficher le fichier .cs|.csImageEditorUserControl.Designer.cs126.15 Ko31/10/2018 18:32:52-refusé-

Utilisation de l'explorateur de code

  • Navigation :
    • Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
    • Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
    • La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
    • Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
  • Affichage :
    • Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
  • Actions :
    • Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.

Document créé le 30/10/2009, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/cs-photobrol-source-rf-view/controls/ImageEditorUserControl.cs.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.