MainWindow.cs 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632
  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using System.Drawing.Drawing2D;
  8. using System.IO;
  9. using System.Drawing.Imaging;
  10. namespace GraphicalCS
  11. {
  12. /// <summary>
  13. /// Summary description for MainWindow.
  14. /// </summary>
  15. public class MainWindow : System.Windows.Forms.Form
  16. {
  17. internal System.Windows.Forms.Button AddFilledRectangle;
  18. internal System.Windows.Forms.Button AddHollowRectangle;
  19. internal System.Windows.Forms.Button AddPoint;
  20. internal System.Windows.Forms.PictureBox Drawing;
  21. private System.Windows.Forms.Button AddLine;
  22. internal System.Windows.Forms.Button AddHollowEllipse;
  23. internal System.Windows.Forms.Button AddFilledEllipse;
  24. private System.Windows.Forms.Button AddCircle;
  25. private System.Windows.Forms.Button AddFillCircle;
  26. private System.Windows.Forms.Button AddPath;
  27. private System.Windows.Forms.Button btnEraser;
  28. private System.Windows.Forms.GroupBox grpTool;
  29. private System.Windows.Forms.MainMenu mainMenu;
  30. private System.Windows.Forms.MenuItem menuFile;
  31. private System.Windows.Forms.MenuItem menuNew;
  32. private System.Windows.Forms.MenuItem menuOpen;
  33. private System.Windows.Forms.MenuItem menuSave;
  34. private System.Windows.Forms.MenuItem menuSaveAs;
  35. private System.Windows.Forms.MenuItem menuItem5;
  36. private System.Windows.Forms.MenuItem menuExit;
  37. private System.Windows.Forms.MenuItem menuItemEs;
  38. private System.Windows.Forms.MenuItem menuItemSize1;
  39. private System.Windows.Forms.MenuItem menuItemmenuItemSize2;
  40. private System.Windows.Forms.MenuItem menuItemSize3;
  41. private System.Windows.Forms.ContextMenu cntMenu;
  42. private System.Windows.Forms.Button btnText;
  43. private System.Windows.Forms.MenuItem menuItemCA;
  44. private System.Windows.Forms.Button btnCircleAt;
  45. private System.Windows.Forms.StatusBar statusBar;
  46. private System.Windows.Forms.StatusBarPanel statusBarImageType;
  47. private System.Windows.Forms.StatusBarPanel statusBarPoint;
  48. private System.Windows.Forms.SaveFileDialog saveFileDialog;
  49. private System.Windows.Forms.OpenFileDialog openFileDialog;
  50. private System.Windows.Forms.Button AddPolygon;
  51. private System.Windows.Forms.MenuItem menuItemClose;
  52. private System.Windows.Forms.Button Black;
  53. private System.Windows.Forms.Button White;
  54. private System.Windows.Forms.Button Red;
  55. private System.Windows.Forms.Button blue;
  56. private System.Windows.Forms.Button Yellow;
  57. private System.Windows.Forms.Button Cyan;
  58. private System.Windows.Forms.Button Magenta;
  59. private System.Windows.Forms.Button LawnGreen;
  60. private System.Windows.Forms.Button btnColor;
  61. private System.Windows.Forms.Button MoreColor;
  62. private System.Windows.Forms.GroupBox ColorBox;
  63. private System.Windows.Forms.ColorDialog colorDialog;
  64. private System.Windows.Forms.Button AddCurve;
  65. private System.Windows.Forms.ContextMenu Curvecontext;
  66. private System.Windows.Forms.MenuItem Curve;
  67. private System.Windows.Forms.MenuItem ClosedCurve;
  68. private System.Windows.Forms.MenuItem menuItemLw;
  69. private System.Windows.Forms.MenuItem menuBeziers;
  70. private System.Windows.Forms.MenuItem Example;
  71. private System.Windows.Forms.MenuItem Advance;
  72. private System.Windows.Forms.MenuItem FadeInOut;
  73. private System.Windows.Forms.MenuItem GrayScale;
  74. private System.Windows.Forms.MenuItem GrayScale1;
  75. private System.Windows.Forms.MenuItem GrayScale2;
  76. private System.Windows.Forms.MenuItem grayScale3;
  77. private System.Windows.Forms.MenuItem GrayScale4;
  78. private System.Windows.Forms.MenuItem Inverse;
  79. private System.Windows.Forms.MenuItem Flashligt;
  80. private System.Windows.Forms.MenuItem BlurAndSharpen;
  81. private System.Windows.Forms.MenuItem menuItem1;
  82. private System.Windows.Forms.MenuItem Report;
  83. private System.Windows.Forms.MenuItem Help;
  84. private System.Windows.Forms.MenuItem menuItem2;
  85. private System.Windows.Forms.MenuItem About;
  86. private System.Windows.Forms.Button btnPick;
  87. private System.Windows.Forms.ToolBar toolBar;
  88. private System.Windows.Forms.ImageList imageList;
  89. private System.Windows.Forms.ToolBarButton Undo;
  90. private System.Windows.Forms.ToolBarButton Redu;
  91. private System.Windows.Forms.ContextMenu ToolContext;
  92. private System.Windows.Forms.MenuItem Change;
  93. private System.Windows.Forms.MenuItem NotChange;
  94. private System.Windows.Forms.ContextMenu ToolContext2;
  95. private System.Windows.Forms.MenuItem Change2;
  96. private System.Windows.Forms.MenuItem NotChange2;
  97. private System.ComponentModel.IContainer components;
  98. /// <summary>
  99. /// 图形枚举。
  100. /// </summary>
  101. public enum ImageType
  102. {
  103. Empty,
  104. Point,
  105. Line,
  106. Rectangle,
  107. FillRectangle,
  108. Circle,
  109. FillCircle,
  110. Ellipse,
  111. FillEllipse,
  112. Path,
  113. Eraser,
  114. Text,
  115. CircleAt,
  116. Polygon,
  117. Curve,
  118. ClosedCurve,
  119. Beziers,
  120. Set,
  121. Pick
  122. }
  123. public MainWindow()
  124. {
  125. //
  126. // Required for Windows Form Designer support
  127. //
  128. InitializeComponent();
  129. //
  130. // TODO: Add any constructor code after InitializeComponent call
  131. //
  132. this.SetStyle(ControlStyles.DoubleBuffer | //双重缓冲
  133. ControlStyles.UserPaint |
  134. ControlStyles.AllPaintingInWmPaint,
  135. true);
  136. this.UpdateStyles();
  137. }
  138. /// <summary>
  139. /// Clean up any resources being used.
  140. /// </summary>
  141. protected override void Dispose( bool disposing )
  142. {
  143. if( disposing )
  144. {
  145. if (components != null)
  146. {
  147. components.Dispose();
  148. }
  149. }
  150. base.Dispose( disposing );
  151. }
  152. #region Windows Form Designer generated code
  153. /// <summary>
  154. /// 主体窗架生成
  155. /// </summary>
  156. private void InitializeComponent()
  157. {
  158. this.components = new System.ComponentModel.Container();
  159. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainWindow));
  160. this.AddFilledRectangle = new System.Windows.Forms.Button();
  161. this.AddHollowRectangle = new System.Windows.Forms.Button();
  162. this.AddPoint = new System.Windows.Forms.Button();
  163. this.Drawing = new System.Windows.Forms.PictureBox();
  164. this.cntMenu = new System.Windows.Forms.ContextMenu();
  165. this.menuItemEs = new System.Windows.Forms.MenuItem();
  166. this.menuItemSize1 = new System.Windows.Forms.MenuItem();
  167. this.menuItemmenuItemSize2 = new System.Windows.Forms.MenuItem();
  168. this.menuItemSize3 = new System.Windows.Forms.MenuItem();
  169. this.menuItemCA = new System.Windows.Forms.MenuItem();
  170. this.menuItemClose = new System.Windows.Forms.MenuItem();
  171. this.menuItemLw = new System.Windows.Forms.MenuItem();
  172. this.Advance = new System.Windows.Forms.MenuItem();
  173. this.FadeInOut = new System.Windows.Forms.MenuItem();
  174. this.GrayScale = new System.Windows.Forms.MenuItem();
  175. this.GrayScale1 = new System.Windows.Forms.MenuItem();
  176. this.GrayScale2 = new System.Windows.Forms.MenuItem();
  177. this.grayScale3 = new System.Windows.Forms.MenuItem();
  178. this.GrayScale4 = new System.Windows.Forms.MenuItem();
  179. this.Inverse = new System.Windows.Forms.MenuItem();
  180. this.Flashligt = new System.Windows.Forms.MenuItem();
  181. this.BlurAndSharpen = new System.Windows.Forms.MenuItem();
  182. this.AddHollowEllipse = new System.Windows.Forms.Button();
  183. this.AddFilledEllipse = new System.Windows.Forms.Button();
  184. this.AddLine = new System.Windows.Forms.Button();
  185. this.AddCircle = new System.Windows.Forms.Button();
  186. this.grpTool = new System.Windows.Forms.GroupBox();
  187. this.AddCurve = new System.Windows.Forms.Button();
  188. this.Curvecontext = new System.Windows.Forms.ContextMenu();
  189. this.Curve = new System.Windows.Forms.MenuItem();
  190. this.ClosedCurve = new System.Windows.Forms.MenuItem();
  191. this.AddPolygon = new System.Windows.Forms.Button();
  192. this.btnCircleAt = new System.Windows.Forms.Button();
  193. this.btnEraser = new System.Windows.Forms.Button();
  194. this.AddPath = new System.Windows.Forms.Button();
  195. this.AddFillCircle = new System.Windows.Forms.Button();
  196. this.btnText = new System.Windows.Forms.Button();
  197. this.mainMenu = new System.Windows.Forms.MainMenu(this.components);
  198. this.menuFile = new System.Windows.Forms.MenuItem();
  199. this.menuNew = new System.Windows.Forms.MenuItem();
  200. this.menuOpen = new System.Windows.Forms.MenuItem();
  201. this.menuSave = new System.Windows.Forms.MenuItem();
  202. this.menuSaveAs = new System.Windows.Forms.MenuItem();
  203. this.menuItem5 = new System.Windows.Forms.MenuItem();
  204. this.menuExit = new System.Windows.Forms.MenuItem();
  205. this.Example = new System.Windows.Forms.MenuItem();
  206. this.menuBeziers = new System.Windows.Forms.MenuItem();
  207. this.menuItem1 = new System.Windows.Forms.MenuItem();
  208. this.Report = new System.Windows.Forms.MenuItem();
  209. this.Help = new System.Windows.Forms.MenuItem();
  210. this.menuItem2 = new System.Windows.Forms.MenuItem();
  211. this.About = new System.Windows.Forms.MenuItem();
  212. this.statusBar = new System.Windows.Forms.StatusBar();
  213. this.statusBarImageType = new System.Windows.Forms.StatusBarPanel();
  214. this.statusBarPoint = new System.Windows.Forms.StatusBarPanel();
  215. this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
  216. this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
  217. this.btnColor = new System.Windows.Forms.Button();
  218. this.Magenta = new System.Windows.Forms.Button();
  219. this.blue = new System.Windows.Forms.Button();
  220. this.Red = new System.Windows.Forms.Button();
  221. this.White = new System.Windows.Forms.Button();
  222. this.Black = new System.Windows.Forms.Button();
  223. this.Yellow = new System.Windows.Forms.Button();
  224. this.LawnGreen = new System.Windows.Forms.Button();
  225. this.Cyan = new System.Windows.Forms.Button();
  226. this.MoreColor = new System.Windows.Forms.Button();
  227. this.ColorBox = new System.Windows.Forms.GroupBox();
  228. this.colorDialog = new System.Windows.Forms.ColorDialog();
  229. this.btnPick = new System.Windows.Forms.Button();
  230. this.toolBar = new System.Windows.Forms.ToolBar();
  231. this.Undo = new System.Windows.Forms.ToolBarButton();
  232. this.ToolContext = new System.Windows.Forms.ContextMenu();
  233. this.Change = new System.Windows.Forms.MenuItem();
  234. this.NotChange = new System.Windows.Forms.MenuItem();
  235. this.Redu = new System.Windows.Forms.ToolBarButton();
  236. this.ToolContext2 = new System.Windows.Forms.ContextMenu();
  237. this.Change2 = new System.Windows.Forms.MenuItem();
  238. this.NotChange2 = new System.Windows.Forms.MenuItem();
  239. this.imageList = new System.Windows.Forms.ImageList(this.components);
  240. ((System.ComponentModel.ISupportInitialize)(this.Drawing)).BeginInit();
  241. this.grpTool.SuspendLayout();
  242. ((System.ComponentModel.ISupportInitialize)(this.statusBarImageType)).BeginInit();
  243. ((System.ComponentModel.ISupportInitialize)(this.statusBarPoint)).BeginInit();
  244. this.ColorBox.SuspendLayout();
  245. this.SuspendLayout();
  246. //
  247. // AddFilledRectangle
  248. //
  249. this.AddFilledRectangle.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  250. this.AddFilledRectangle.BackColor = System.Drawing.SystemColors.ControlLightLight;
  251. this.AddFilledRectangle.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("AddFilledRectangle.BackgroundImage")));
  252. this.AddFilledRectangle.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  253. this.AddFilledRectangle.Image = ((System.Drawing.Image)(resources.GetObject("AddFilledRectangle.Image")));
  254. this.AddFilledRectangle.Location = new System.Drawing.Point(48, 48);
  255. this.AddFilledRectangle.Name = "AddFilledRectangle";
  256. this.AddFilledRectangle.Size = new System.Drawing.Size(26, 26);
  257. this.AddFilledRectangle.TabIndex = 17;
  258. this.AddFilledRectangle.UseVisualStyleBackColor = false;
  259. this.AddFilledRectangle.Click += new System.EventHandler(this.AddFilledRectangle_Click);
  260. //
  261. // AddHollowRectangle
  262. //
  263. this.AddHollowRectangle.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  264. this.AddHollowRectangle.BackColor = System.Drawing.SystemColors.ControlLightLight;
  265. this.AddHollowRectangle.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("AddHollowRectangle.BackgroundImage")));
  266. this.AddHollowRectangle.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  267. this.AddHollowRectangle.Image = ((System.Drawing.Image)(resources.GetObject("AddHollowRectangle.Image")));
  268. this.AddHollowRectangle.Location = new System.Drawing.Point(8, 48);
  269. this.AddHollowRectangle.Name = "AddHollowRectangle";
  270. this.AddHollowRectangle.Size = new System.Drawing.Size(26, 26);
  271. this.AddHollowRectangle.TabIndex = 16;
  272. this.AddHollowRectangle.UseVisualStyleBackColor = false;
  273. this.AddHollowRectangle.Click += new System.EventHandler(this.AddHollowRectangle_Click);
  274. //
  275. // AddPoint
  276. //
  277. this.AddPoint.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  278. this.AddPoint.BackColor = System.Drawing.SystemColors.ControlLightLight;
  279. this.AddPoint.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("AddPoint.BackgroundImage")));
  280. this.AddPoint.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  281. this.AddPoint.Location = new System.Drawing.Point(8, 16);
  282. this.AddPoint.Name = "AddPoint";
  283. this.AddPoint.Size = new System.Drawing.Size(26, 26);
  284. this.AddPoint.TabIndex = 15;
  285. this.AddPoint.UseVisualStyleBackColor = false;
  286. this.AddPoint.Click += new System.EventHandler(this.AddPoint_Click);
  287. //
  288. // Drawing
  289. //
  290. this.Drawing.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  291. | System.Windows.Forms.AnchorStyles.Left)
  292. | System.Windows.Forms.AnchorStyles.Right)));
  293. this.Drawing.BackColor = System.Drawing.SystemColors.ControlLightLight;
  294. this.Drawing.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("Drawing.BackgroundImage")));
  295. this.Drawing.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
  296. this.Drawing.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  297. this.Drawing.ContextMenu = this.cntMenu;
  298. this.Drawing.Location = new System.Drawing.Point(8, 8);
  299. this.Drawing.Name = "Drawing";
  300. this.Drawing.Size = new System.Drawing.Size(567, 427);
  301. this.Drawing.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
  302. this.Drawing.TabIndex = 14;
  303. this.Drawing.TabStop = false;
  304. this.Drawing.Paint += new System.Windows.Forms.PaintEventHandler(this.Drawing_Paint);
  305. this.Drawing.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Drawing_MouseDown);
  306. this.Drawing.MouseEnter += new System.EventHandler(this.Drawing_MouseEnter);
  307. this.Drawing.MouseLeave += new System.EventHandler(this.Drawing_MouseLeave);
  308. this.Drawing.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Drawing_MouseMove);
  309. this.Drawing.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Drawing_MouseUp);
  310. //
  311. // cntMenu
  312. //
  313. this.cntMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  314. this.menuItemEs,
  315. this.menuItemCA,
  316. this.menuItemClose,
  317. this.menuItemLw,
  318. this.Advance});
  319. //
  320. // menuItemEs
  321. //
  322. this.menuItemEs.Index = 0;
  323. this.menuItemEs.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  324. this.menuItemSize1,
  325. this.menuItemmenuItemSize2,
  326. this.menuItemSize3});
  327. this.menuItemEs.Text = "&EraserSize";
  328. //
  329. // menuItemSize1
  330. //
  331. this.menuItemSize1.Index = 0;
  332. this.menuItemSize1.Text = "&Small";
  333. this.menuItemSize1.Click += new System.EventHandler(this.menuItemSize1_Click);
  334. //
  335. // menuItemmenuItemSize2
  336. //
  337. this.menuItemmenuItemSize2.Index = 1;
  338. this.menuItemmenuItemSize2.Text = "&Middle";
  339. this.menuItemmenuItemSize2.Click += new System.EventHandler(this.menuItemmenuItemSize2_Click);
  340. //
  341. // menuItemSize3
  342. //
  343. this.menuItemSize3.Index = 2;
  344. this.menuItemSize3.Text = "&Large";
  345. this.menuItemSize3.Click += new System.EventHandler(this.menuItemSize3_Click);
  346. //
  347. // menuItemCA
  348. //
  349. this.menuItemCA.Index = 1;
  350. this.menuItemCA.Text = "Circle &At";
  351. this.menuItemCA.Click += new System.EventHandler(this.menuItemCA_Click);
  352. //
  353. // menuItemClose
  354. //
  355. this.menuItemClose.Index = 2;
  356. this.menuItemClose.Text = "&Close";
  357. this.menuItemClose.Click += new System.EventHandler(this.menuItemClose_Click);
  358. //
  359. // menuItemLw
  360. //
  361. this.menuItemLw.Index = 3;
  362. this.menuItemLw.Text = "&LineWidth";
  363. this.menuItemLw.Click += new System.EventHandler(this.menuItemLw_Click);
  364. //
  365. // Advance
  366. //
  367. this.Advance.Index = 4;
  368. this.Advance.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  369. this.FadeInOut,
  370. this.GrayScale,
  371. this.Inverse,
  372. this.Flashligt,
  373. this.BlurAndSharpen});
  374. this.Advance.Text = "&Advance";
  375. //
  376. // FadeInOut
  377. //
  378. this.FadeInOut.Index = 0;
  379. this.FadeInOut.Text = "&FadeInOut";
  380. this.FadeInOut.Click += new System.EventHandler(this.FadeInOut_Click);
  381. //
  382. // GrayScale
  383. //
  384. this.GrayScale.Index = 1;
  385. this.GrayScale.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  386. this.GrayScale1,
  387. this.GrayScale2,
  388. this.grayScale3,
  389. this.GrayScale4});
  390. this.GrayScale.Text = "&GrayScale";
  391. //
  392. // GrayScale1
  393. //
  394. this.GrayScale1.Index = 0;
  395. this.GrayScale1.Text = "GrayScale&1";
  396. this.GrayScale1.Click += new System.EventHandler(this.GrayScale1_Click);
  397. //
  398. // GrayScale2
  399. //
  400. this.GrayScale2.Index = 1;
  401. this.GrayScale2.Text = "GrayScale&2";
  402. this.GrayScale2.Click += new System.EventHandler(this.GrayScale2_Click);
  403. //
  404. // grayScale3
  405. //
  406. this.grayScale3.Index = 2;
  407. this.grayScale3.Text = "GrayScale&3";
  408. this.grayScale3.Click += new System.EventHandler(this.grayScale3_Click);
  409. //
  410. // GrayScale4
  411. //
  412. this.GrayScale4.Index = 3;
  413. this.GrayScale4.Text = "GrayScale&4";
  414. this.GrayScale4.Click += new System.EventHandler(this.GrayScale4_Click);
  415. //
  416. // Inverse
  417. //
  418. this.Inverse.Index = 2;
  419. this.Inverse.Text = "&Inverse";
  420. this.Inverse.Click += new System.EventHandler(this.Inverse_Click);
  421. //
  422. // Flashligt
  423. //
  424. this.Flashligt.Index = 3;
  425. this.Flashligt.Text = "&Flashligt";
  426. this.Flashligt.Click += new System.EventHandler(this.Flashligt_Click);
  427. //
  428. // BlurAndSharpen
  429. //
  430. this.BlurAndSharpen.Index = 4;
  431. this.BlurAndSharpen.Text = "&BlurAndSharpen";
  432. this.BlurAndSharpen.Click += new System.EventHandler(this.BlurAndSharpen_Click);
  433. //
  434. // AddHollowEllipse
  435. //
  436. this.AddHollowEllipse.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  437. this.AddHollowEllipse.BackColor = System.Drawing.SystemColors.ControlLightLight;
  438. this.AddHollowEllipse.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("AddHollowEllipse.BackgroundImage")));
  439. this.AddHollowEllipse.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  440. this.AddHollowEllipse.Image = ((System.Drawing.Image)(resources.GetObject("AddHollowEllipse.Image")));
  441. this.AddHollowEllipse.Location = new System.Drawing.Point(8, 80);
  442. this.AddHollowEllipse.Name = "AddHollowEllipse";
  443. this.AddHollowEllipse.Size = new System.Drawing.Size(26, 26);
  444. this.AddHollowEllipse.TabIndex = 19;
  445. this.AddHollowEllipse.UseVisualStyleBackColor = false;
  446. this.AddHollowEllipse.Click += new System.EventHandler(this.AddHollowEllipse_Click);
  447. //
  448. // AddFilledEllipse
  449. //
  450. this.AddFilledEllipse.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  451. this.AddFilledEllipse.BackColor = System.Drawing.SystemColors.ControlLightLight;
  452. this.AddFilledEllipse.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("AddFilledEllipse.BackgroundImage")));
  453. this.AddFilledEllipse.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  454. this.AddFilledEllipse.Image = ((System.Drawing.Image)(resources.GetObject("AddFilledEllipse.Image")));
  455. this.AddFilledEllipse.Location = new System.Drawing.Point(48, 80);
  456. this.AddFilledEllipse.Name = "AddFilledEllipse";
  457. this.AddFilledEllipse.Size = new System.Drawing.Size(26, 26);
  458. this.AddFilledEllipse.TabIndex = 22;
  459. this.AddFilledEllipse.UseVisualStyleBackColor = false;
  460. this.AddFilledEllipse.Click += new System.EventHandler(this.AddFilledEllipse_Click);
  461. //
  462. // AddLine
  463. //
  464. this.AddLine.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  465. this.AddLine.BackColor = System.Drawing.SystemColors.ControlLightLight;
  466. this.AddLine.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("AddLine.BackgroundImage")));
  467. this.AddLine.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  468. this.AddLine.Location = new System.Drawing.Point(48, 16);
  469. this.AddLine.Name = "AddLine";
  470. this.AddLine.Size = new System.Drawing.Size(26, 26);
  471. this.AddLine.TabIndex = 23;
  472. this.AddLine.UseVisualStyleBackColor = false;
  473. this.AddLine.Click += new System.EventHandler(this.AddLine_Click);
  474. //
  475. // AddCircle
  476. //
  477. this.AddCircle.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  478. this.AddCircle.BackColor = System.Drawing.SystemColors.ControlLightLight;
  479. this.AddCircle.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("AddCircle.BackgroundImage")));
  480. this.AddCircle.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  481. this.AddCircle.Image = ((System.Drawing.Image)(resources.GetObject("AddCircle.Image")));
  482. this.AddCircle.Location = new System.Drawing.Point(8, 112);
  483. this.AddCircle.Name = "AddCircle";
  484. this.AddCircle.Size = new System.Drawing.Size(26, 26);
  485. this.AddCircle.TabIndex = 24;
  486. this.AddCircle.UseVisualStyleBackColor = false;
  487. this.AddCircle.Click += new System.EventHandler(this.AddCircle_Click);
  488. //
  489. // grpTool
  490. //
  491. this.grpTool.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  492. this.grpTool.Controls.Add(this.AddCurve);
  493. this.grpTool.Controls.Add(this.AddPolygon);
  494. this.grpTool.Controls.Add(this.btnCircleAt);
  495. this.grpTool.Controls.Add(this.btnEraser);
  496. this.grpTool.Controls.Add(this.AddPath);
  497. this.grpTool.Controls.Add(this.AddFillCircle);
  498. this.grpTool.Controls.Add(this.AddPoint);
  499. this.grpTool.Controls.Add(this.AddLine);
  500. this.grpTool.Controls.Add(this.AddHollowRectangle);
  501. this.grpTool.Controls.Add(this.AddFilledRectangle);
  502. this.grpTool.Controls.Add(this.AddHollowEllipse);
  503. this.grpTool.Controls.Add(this.AddFilledEllipse);
  504. this.grpTool.Controls.Add(this.AddCircle);
  505. this.grpTool.Controls.Add(this.btnText);
  506. this.grpTool.Location = new System.Drawing.Point(647, 8);
  507. this.grpTool.Name = "grpTool";
  508. this.grpTool.Size = new System.Drawing.Size(82, 240);
  509. this.grpTool.TabIndex = 25;
  510. this.grpTool.TabStop = false;
  511. //
  512. // AddCurve
  513. //
  514. this.AddCurve.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  515. this.AddCurve.BackColor = System.Drawing.SystemColors.ControlLightLight;
  516. this.AddCurve.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("AddCurve.BackgroundImage")));
  517. this.AddCurve.ContextMenu = this.Curvecontext;
  518. this.AddCurve.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  519. this.AddCurve.Location = new System.Drawing.Point(48, 208);
  520. this.AddCurve.Name = "AddCurve";
  521. this.AddCurve.Size = new System.Drawing.Size(26, 26);
  522. this.AddCurve.TabIndex = 30;
  523. this.AddCurve.UseVisualStyleBackColor = false;
  524. //
  525. // Curvecontext
  526. //
  527. this.Curvecontext.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  528. this.Curve,
  529. this.ClosedCurve});
  530. //
  531. // Curve
  532. //
  533. this.Curve.Index = 0;
  534. this.Curve.Text = "Curve";
  535. this.Curve.Click += new System.EventHandler(this.Curve_Click);
  536. //
  537. // ClosedCurve
  538. //
  539. this.ClosedCurve.Index = 1;
  540. this.ClosedCurve.Text = "ClosedCurve";
  541. this.ClosedCurve.Click += new System.EventHandler(this.ClosedCurve_Click);
  542. //
  543. // AddPolygon
  544. //
  545. this.AddPolygon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  546. this.AddPolygon.BackColor = System.Drawing.SystemColors.ControlLightLight;
  547. this.AddPolygon.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("AddPolygon.BackgroundImage")));
  548. this.AddPolygon.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  549. this.AddPolygon.Location = new System.Drawing.Point(8, 208);
  550. this.AddPolygon.Name = "AddPolygon";
  551. this.AddPolygon.Size = new System.Drawing.Size(26, 26);
  552. this.AddPolygon.TabIndex = 29;
  553. this.AddPolygon.UseVisualStyleBackColor = false;
  554. this.AddPolygon.Click += new System.EventHandler(this.AddPolygon_Click);
  555. //
  556. // btnCircleAt
  557. //
  558. this.btnCircleAt.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  559. this.btnCircleAt.BackColor = System.Drawing.SystemColors.ControlLightLight;
  560. this.btnCircleAt.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnCircleAt.BackgroundImage")));
  561. this.btnCircleAt.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  562. this.btnCircleAt.Location = new System.Drawing.Point(48, 176);
  563. this.btnCircleAt.Name = "btnCircleAt";
  564. this.btnCircleAt.Size = new System.Drawing.Size(26, 26);
  565. this.btnCircleAt.TabIndex = 28;
  566. this.btnCircleAt.UseVisualStyleBackColor = false;
  567. this.btnCircleAt.Click += new System.EventHandler(this.btnCircleAt_Click);
  568. //
  569. // btnEraser
  570. //
  571. this.btnEraser.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  572. this.btnEraser.BackColor = System.Drawing.SystemColors.ControlLightLight;
  573. this.btnEraser.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnEraser.BackgroundImage")));
  574. this.btnEraser.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  575. this.btnEraser.Location = new System.Drawing.Point(48, 144);
  576. this.btnEraser.Name = "btnEraser";
  577. this.btnEraser.Size = new System.Drawing.Size(26, 26);
  578. this.btnEraser.TabIndex = 27;
  579. this.btnEraser.UseVisualStyleBackColor = false;
  580. this.btnEraser.Click += new System.EventHandler(this.btnEraser_Click);
  581. //
  582. // AddPath
  583. //
  584. this.AddPath.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  585. this.AddPath.BackColor = System.Drawing.SystemColors.ControlLightLight;
  586. this.AddPath.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("AddPath.BackgroundImage")));
  587. this.AddPath.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  588. this.AddPath.Image = ((System.Drawing.Image)(resources.GetObject("AddPath.Image")));
  589. this.AddPath.Location = new System.Drawing.Point(8, 144);
  590. this.AddPath.Name = "AddPath";
  591. this.AddPath.Size = new System.Drawing.Size(26, 26);
  592. this.AddPath.TabIndex = 26;
  593. this.AddPath.UseVisualStyleBackColor = false;
  594. this.AddPath.Click += new System.EventHandler(this.AddPath_Click);
  595. //
  596. // AddFillCircle
  597. //
  598. this.AddFillCircle.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  599. this.AddFillCircle.BackColor = System.Drawing.SystemColors.ControlLightLight;
  600. this.AddFillCircle.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("AddFillCircle.BackgroundImage")));
  601. this.AddFillCircle.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  602. this.AddFillCircle.Image = ((System.Drawing.Image)(resources.GetObject("AddFillCircle.Image")));
  603. this.AddFillCircle.Location = new System.Drawing.Point(48, 112);
  604. this.AddFillCircle.Name = "AddFillCircle";
  605. this.AddFillCircle.Size = new System.Drawing.Size(26, 26);
  606. this.AddFillCircle.TabIndex = 25;
  607. this.AddFillCircle.UseVisualStyleBackColor = false;
  608. this.AddFillCircle.Click += new System.EventHandler(this.AddFillCircle_Click);
  609. //
  610. // btnText
  611. //
  612. this.btnText.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  613. this.btnText.BackColor = System.Drawing.SystemColors.ControlLightLight;
  614. this.btnText.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnText.BackgroundImage")));
  615. this.btnText.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  616. this.btnText.Location = new System.Drawing.Point(8, 176);
  617. this.btnText.Name = "btnText";
  618. this.btnText.Size = new System.Drawing.Size(26, 26);
  619. this.btnText.TabIndex = 26;
  620. this.btnText.UseVisualStyleBackColor = false;
  621. this.btnText.Click += new System.EventHandler(this.btnText_Click);
  622. //
  623. // mainMenu
  624. //
  625. this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  626. this.menuFile,
  627. this.Example,
  628. this.menuItem1});
  629. //
  630. // menuFile
  631. //
  632. this.menuFile.Index = 0;
  633. this.menuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  634. this.menuNew,
  635. this.menuOpen,
  636. this.menuSave,
  637. this.menuSaveAs,
  638. this.menuItem5,
  639. this.menuExit});
  640. this.menuFile.Text = "&File";
  641. //
  642. // menuNew
  643. //
  644. this.menuNew.Index = 0;
  645. this.menuNew.Text = "&New";
  646. this.menuNew.Click += new System.EventHandler(this.menuNew_Click);
  647. //
  648. // menuOpen
  649. //
  650. this.menuOpen.Index = 1;
  651. this.menuOpen.Text = "&Open";
  652. this.menuOpen.Click += new System.EventHandler(this.menuOpen_Click);
  653. //
  654. // menuSave
  655. //
  656. this.menuSave.Index = 2;
  657. this.menuSave.Text = "&Save";
  658. this.menuSave.Click += new System.EventHandler(this.menuSave_Click);
  659. //
  660. // menuSaveAs
  661. //
  662. this.menuSaveAs.Index = 3;
  663. this.menuSaveAs.Text = "Save &as...";
  664. this.menuSaveAs.Click += new System.EventHandler(this.menuSaveAs_Click);
  665. //
  666. // menuItem5
  667. //
  668. this.menuItem5.Index = 4;
  669. this.menuItem5.Text = "-";
  670. //
  671. // menuExit
  672. //
  673. this.menuExit.Index = 5;
  674. this.menuExit.Text = "&Exit";
  675. this.menuExit.Click += new System.EventHandler(this.menuExit_Click);
  676. //
  677. // Example
  678. //
  679. this.Example.Index = 1;
  680. this.Example.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  681. this.menuBeziers});
  682. this.Example.Text = "&Example";
  683. //
  684. // menuBeziers
  685. //
  686. this.menuBeziers.Index = 0;
  687. this.menuBeziers.Text = "&Window";
  688. this.menuBeziers.Click += new System.EventHandler(this.menuBeziers_Click);
  689. //
  690. // menuItem1
  691. //
  692. this.menuItem1.Index = 2;
  693. this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  694. this.Report,
  695. this.Help,
  696. this.menuItem2,
  697. this.About});
  698. this.menuItem1.Text = "&Help";
  699. //
  700. // Report
  701. //
  702. this.Report.Index = 0;
  703. this.Report.Text = "&Code Report";
  704. this.Report.Click += new System.EventHandler(this.Report_Click);
  705. //
  706. // Help
  707. //
  708. this.Help.Index = 1;
  709. this.Help.Text = "&ProgrammeHelp";
  710. this.Help.Click += new System.EventHandler(this.Help_Click);
  711. //
  712. // menuItem2
  713. //
  714. this.menuItem2.Index = 2;
  715. this.menuItem2.Text = "-";
  716. //
  717. // About
  718. //
  719. this.About.Index = 3;
  720. this.About.Text = "&About";
  721. this.About.Click += new System.EventHandler(this.About_Click);
  722. //
  723. // statusBar
  724. //
  725. this.statusBar.Location = new System.Drawing.Point(0, 443);
  726. this.statusBar.Name = "statusBar";
  727. this.statusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
  728. this.statusBarImageType,
  729. this.statusBarPoint});
  730. this.statusBar.ShowPanels = true;
  731. this.statusBar.Size = new System.Drawing.Size(744, 22);
  732. this.statusBar.TabIndex = 26;
  733. //
  734. // statusBarImageType
  735. //
  736. this.statusBarImageType.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
  737. this.statusBarImageType.Name = "statusBarImageType";
  738. this.statusBarImageType.Width = 675;
  739. //
  740. // statusBarPoint
  741. //
  742. this.statusBarPoint.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents;
  743. this.statusBarPoint.Name = "statusBarPoint";
  744. this.statusBarPoint.Text = "Point:";
  745. this.statusBarPoint.Width = 52;
  746. //
  747. // saveFileDialog
  748. //
  749. this.saveFileDialog.FileName = "NewFile";
  750. this.saveFileDialog.Filter = "JPeg Image(*.jpg)|*.jpg|Bitmap Image(*.bmp)|*.bmp|Gif Image(*.gif)|*.gif";
  751. this.saveFileDialog.FilterIndex = 2;
  752. this.saveFileDialog.Title = "Save As";
  753. //
  754. // openFileDialog
  755. //
  756. this.openFileDialog.Filter = "JPeg Image(*.jpg)|*.jpg|Bitmap Image(*.bmp)|*.bmp|Gif Image(*.gif)|*.gif";
  757. this.openFileDialog.FilterIndex = 2;
  758. this.openFileDialog.Title = "Open File";
  759. //
  760. // btnColor
  761. //
  762. this.btnColor.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  763. | System.Windows.Forms.AnchorStyles.Right)));
  764. this.btnColor.BackColor = System.Drawing.SystemColors.ControlLightLight;
  765. this.btnColor.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  766. this.btnColor.Location = new System.Drawing.Point(12, 10);
  767. this.btnColor.Name = "btnColor";
  768. this.btnColor.Size = new System.Drawing.Size(24, 24);
  769. this.btnColor.TabIndex = 32;
  770. this.btnColor.UseVisualStyleBackColor = false;
  771. //
  772. // Magenta
  773. //
  774. this.Magenta.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  775. | System.Windows.Forms.AnchorStyles.Right)));
  776. this.Magenta.BackColor = System.Drawing.Color.Magenta;
  777. this.Magenta.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  778. this.Magenta.Location = new System.Drawing.Point(24, 88);
  779. this.Magenta.Name = "Magenta";
  780. this.Magenta.Size = new System.Drawing.Size(15, 15);
  781. this.Magenta.TabIndex = 31;
  782. this.Magenta.UseVisualStyleBackColor = false;
  783. this.Magenta.Click += new System.EventHandler(this.Magenta_Click);
  784. //
  785. // blue
  786. //
  787. this.blue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  788. | System.Windows.Forms.AnchorStyles.Right)));
  789. this.blue.BackColor = System.Drawing.Color.Blue;
  790. this.blue.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  791. this.blue.Location = new System.Drawing.Point(24, 56);
  792. this.blue.Name = "blue";
  793. this.blue.Size = new System.Drawing.Size(15, 15);
  794. this.blue.TabIndex = 3;
  795. this.blue.UseVisualStyleBackColor = false;
  796. this.blue.Click += new System.EventHandler(this.blue_Click);
  797. //
  798. // Red
  799. //
  800. this.Red.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  801. | System.Windows.Forms.AnchorStyles.Right)));
  802. this.Red.BackColor = System.Drawing.Color.Red;
  803. this.Red.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  804. this.Red.Location = new System.Drawing.Point(8, 56);
  805. this.Red.Name = "Red";
  806. this.Red.Size = new System.Drawing.Size(15, 15);
  807. this.Red.TabIndex = 2;
  808. this.Red.UseVisualStyleBackColor = false;
  809. this.Red.Click += new System.EventHandler(this.Red_Click);
  810. //
  811. // White
  812. //
  813. this.White.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  814. | System.Windows.Forms.AnchorStyles.Right)));
  815. this.White.BackColor = System.Drawing.Color.White;
  816. this.White.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  817. this.White.Location = new System.Drawing.Point(24, 40);
  818. this.White.Name = "White";
  819. this.White.Size = new System.Drawing.Size(15, 15);
  820. this.White.TabIndex = 1;
  821. this.White.UseVisualStyleBackColor = false;
  822. this.White.Click += new System.EventHandler(this.White_Click);
  823. //
  824. // Black
  825. //
  826. this.Black.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  827. | System.Windows.Forms.AnchorStyles.Right)));
  828. this.Black.BackColor = System.Drawing.Color.Black;
  829. this.Black.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  830. this.Black.Location = new System.Drawing.Point(8, 40);
  831. this.Black.Name = "Black";
  832. this.Black.Size = new System.Drawing.Size(15, 15);
  833. this.Black.TabIndex = 0;
  834. this.Black.UseVisualStyleBackColor = false;
  835. this.Black.Click += new System.EventHandler(this.Black_Click);
  836. //
  837. // Yellow
  838. //
  839. this.Yellow.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  840. | System.Windows.Forms.AnchorStyles.Right)));
  841. this.Yellow.BackColor = System.Drawing.Color.Yellow;
  842. this.Yellow.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  843. this.Yellow.Location = new System.Drawing.Point(8, 72);
  844. this.Yellow.Name = "Yellow";
  845. this.Yellow.Size = new System.Drawing.Size(15, 15);
  846. this.Yellow.TabIndex = 28;
  847. this.Yellow.UseVisualStyleBackColor = false;
  848. this.Yellow.Click += new System.EventHandler(this.Yellow_Click);
  849. //
  850. // LawnGreen
  851. //
  852. this.LawnGreen.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  853. | System.Windows.Forms.AnchorStyles.Right)));
  854. this.LawnGreen.BackColor = System.Drawing.Color.LawnGreen;
  855. this.LawnGreen.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  856. this.LawnGreen.Location = new System.Drawing.Point(24, 72);
  857. this.LawnGreen.Name = "LawnGreen";
  858. this.LawnGreen.Size = new System.Drawing.Size(15, 15);
  859. this.LawnGreen.TabIndex = 29;
  860. this.LawnGreen.UseVisualStyleBackColor = false;
  861. this.LawnGreen.Click += new System.EventHandler(this.LawnGreen_Click);
  862. //
  863. // Cyan
  864. //
  865. this.Cyan.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  866. | System.Windows.Forms.AnchorStyles.Right)));
  867. this.Cyan.BackColor = System.Drawing.Color.Cyan;
  868. this.Cyan.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  869. this.Cyan.Location = new System.Drawing.Point(8, 88);
  870. this.Cyan.Name = "Cyan";
  871. this.Cyan.Size = new System.Drawing.Size(15, 15);
  872. this.Cyan.TabIndex = 30;
  873. this.Cyan.UseVisualStyleBackColor = false;
  874. this.Cyan.Click += new System.EventHandler(this.Cyan_Click);
  875. //
  876. // MoreColor
  877. //
  878. this.MoreColor.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  879. this.MoreColor.BackColor = System.Drawing.SystemColors.HighlightText;
  880. this.MoreColor.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  881. this.MoreColor.Location = new System.Drawing.Point(664, 368);
  882. this.MoreColor.Name = "MoreColor";
  883. this.MoreColor.Size = new System.Drawing.Size(50, 16);
  884. this.MoreColor.TabIndex = 28;
  885. this.MoreColor.Text = "More>>";
  886. this.MoreColor.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  887. this.MoreColor.UseVisualStyleBackColor = false;
  888. this.MoreColor.Click += new System.EventHandler(this.MoreColor_Click);
  889. //
  890. // ColorBox
  891. //
  892. this.ColorBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  893. this.ColorBox.Controls.Add(this.blue);
  894. this.ColorBox.Controls.Add(this.Red);
  895. this.ColorBox.Controls.Add(this.btnColor);
  896. this.ColorBox.Controls.Add(this.Magenta);
  897. this.ColorBox.Controls.Add(this.White);
  898. this.ColorBox.Controls.Add(this.Black);
  899. this.ColorBox.Controls.Add(this.Yellow);
  900. this.ColorBox.Controls.Add(this.LawnGreen);
  901. this.ColorBox.Controls.Add(this.Cyan);
  902. this.ColorBox.Location = new System.Drawing.Point(664, 256);
  903. this.ColorBox.Name = "ColorBox";
  904. this.ColorBox.Size = new System.Drawing.Size(48, 112);
  905. this.ColorBox.TabIndex = 29;
  906. this.ColorBox.TabStop = false;
  907. //
  908. // btnPick
  909. //
  910. this.btnPick.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  911. this.btnPick.BackColor = System.Drawing.SystemColors.ControlLightLight;
  912. this.btnPick.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnPick.BackgroundImage")));
  913. this.btnPick.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  914. this.btnPick.Location = new System.Drawing.Point(608, 32);
  915. this.btnPick.Name = "btnPick";
  916. this.btnPick.Size = new System.Drawing.Size(26, 26);
  917. this.btnPick.TabIndex = 30;
  918. this.btnPick.UseVisualStyleBackColor = false;
  919. this.btnPick.Click += new System.EventHandler(this.btnPick_Click);
  920. //
  921. // toolBar
  922. //
  923. this.toolBar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  924. this.toolBar.AutoSize = false;
  925. this.toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
  926. this.Undo,
  927. this.Redu});
  928. this.toolBar.ContextMenu = this.ToolContext;
  929. this.toolBar.Dock = System.Windows.Forms.DockStyle.None;
  930. this.toolBar.DropDownArrows = true;
  931. this.toolBar.ImageList = this.imageList;
  932. this.toolBar.Location = new System.Drawing.Point(600, 64);
  933. this.toolBar.Name = "toolBar";
  934. this.toolBar.ShowToolTips = true;
  935. this.toolBar.Size = new System.Drawing.Size(40, 48);
  936. this.toolBar.TabIndex = 31;
  937. //
  938. // Undo
  939. //
  940. this.Undo.DropDownMenu = this.ToolContext;
  941. this.Undo.ImageIndex = 0;
  942. this.Undo.Name = "Undo";
  943. this.Undo.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
  944. //
  945. // ToolContext
  946. //
  947. this.ToolContext.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  948. this.Change,
  949. this.NotChange});
  950. //
  951. // Change
  952. //
  953. this.Change.Index = 0;
  954. this.Change.Text = "Change";
  955. this.Change.Click += new System.EventHandler(this.Change_Click);
  956. //
  957. // NotChange
  958. //
  959. this.NotChange.Index = 1;
  960. this.NotChange.Text = "NotChange";
  961. this.NotChange.Click += new System.EventHandler(this.NotChange_Click);
  962. //
  963. // Redu
  964. //
  965. this.Redu.DropDownMenu = this.ToolContext2;
  966. this.Redu.ImageIndex = 1;
  967. this.Redu.Name = "Redu";
  968. this.Redu.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
  969. //
  970. // ToolContext2
  971. //
  972. this.ToolContext2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  973. this.Change2,
  974. this.NotChange2});
  975. //
  976. // Change2
  977. //
  978. this.Change2.Index = 0;
  979. this.Change2.Text = "rChange";
  980. this.Change2.Click += new System.EventHandler(this.Change2_Click);
  981. //
  982. // NotChange2
  983. //
  984. this.NotChange2.Index = 1;
  985. this.NotChange2.Text = "rNotChange";
  986. this.NotChange2.Click += new System.EventHandler(this.NotChange2_Click);
  987. //
  988. // imageList
  989. //
  990. this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList.ImageStream")));
  991. this.imageList.TransparentColor = System.Drawing.Color.Transparent;
  992. this.imageList.Images.SetKeyName(0, "");
  993. this.imageList.Images.SetKeyName(1, "");
  994. //
  995. // MainWindow
  996. //
  997. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  998. this.ClientSize = new System.Drawing.Size(744, 465);
  999. this.Controls.Add(this.toolBar);
  1000. this.Controls.Add(this.btnPick);
  1001. this.Controls.Add(this.ColorBox);
  1002. this.Controls.Add(this.MoreColor);
  1003. this.Controls.Add(this.statusBar);
  1004. this.Controls.Add(this.grpTool);
  1005. this.Controls.Add(this.Drawing);
  1006. this.Menu = this.mainMenu;
  1007. this.Name = "MainWindow";
  1008. this.Text = "MyPGS";
  1009. ((System.ComponentModel.ISupportInitialize)(this.Drawing)).EndInit();
  1010. this.grpTool.ResumeLayout(false);
  1011. ((System.ComponentModel.ISupportInitialize)(this.statusBarImageType)).EndInit();
  1012. ((System.ComponentModel.ISupportInitialize)(this.statusBarPoint)).EndInit();
  1013. this.ColorBox.ResumeLayout(false);
  1014. this.ResumeLayout(false);
  1015. }
  1016. #endregion
  1017. /// <summary>
  1018. /// 主函数,程序入口点。
  1019. /// </summary>
  1020. [STAThread]
  1021. static void Main()
  1022. {
  1023. Application.Run(new MainWindow());
  1024. }
  1025. #region 申明
  1026. /// <summary>
  1027. /// 图形存储集合等。
  1028. /// </summary>
  1029. DShapeList drawingList = new DShapeList(); //图元
  1030. DShapeList drawingListUndo = new DShapeList(); //Undo保存
  1031. DShapeList tempPoint = new DShapeList(); //多边形、曲线临时顶点
  1032. DShapeList pointViewList = new DShapeList(); //图元顶点框
  1033. DShapeList notchangeList = new DShapeList(); //不移图元
  1034. DShapeList notchangeListUndo = new DShapeList();
  1035. NewForm newForm = new NewForm(); //字体、线宽窗口
  1036. CircleForm newCircle = new CircleForm(); //顶点圆窗口
  1037. ArrayList pointCollection = new ArrayList(); //多边形、曲线顶点集合
  1038. NewRegion regionCollection = new NewRegion(); //图元区域集合
  1039. NewRegion regionCollectionUndo = new NewRegion();
  1040. PointArrayCollection pointArray = new PointArrayCollection(); //图元顶点数组集合
  1041. PointArrayCollection pointArrayUndo = new PointArrayCollection();
  1042. Type drawImageType = new Type(); //图元形状
  1043. Type drawImageTypeUndo = new Type();
  1044. NewRegionArray regionArrayCollection = new NewRegionArray(); //图元顶点区域集合
  1045. NewRegionArray regionArrayCollectionUndo = new NewRegionArray();
  1046. GraphicsPath regionPath; //线、多边形区域路径
  1047. Point[] tempPointArray; //图元顶点临时保存
  1048. Region[] tempRegion; //图元顶点区域临时数组
  1049. Point[] tempMovePoint; //拾取起始点保存
  1050. int regionIndex = 0; //拾取集合索引
  1051. int pointIndex; //拾取顶点索引
  1052. int Distance; //圆半径(临时)
  1053. int diameter; //圆直径(临时)
  1054. bool picked = false; //拾取与否
  1055. bool changed = false; //图元变换
  1056. bool mouseMove = false; //拾取是否移动
  1057. bool eraser = false;
  1058. //零时变量,常量
  1059. private MousePoint newPoint;
  1060. private MousePoint tempChangePoint;
  1061. private ImageType newType;
  1062. private GraphicsPath mousePath;
  1063. private Region newRegion;
  1064. private int EraserSize;
  1065. private Image newImage;
  1066. private string fileName = "NewFile";
  1067. private Color newColor = Color.Black;
  1068. private float lineWidth = 1;
  1069. private ImageType tempType;
  1070. #endregion
  1071. #region 画图事件
  1072. /// <summary>
  1073. /// 画图事件
  1074. /// </summary>
  1075. private void Drawing_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  1076. {
  1077. Graphics displayGraphics = e.Graphics;
  1078. switch(newType)
  1079. {
  1080. case ImageType.Point:
  1081. displayGraphics.DrawRectangle(new Pen(newColor,lineWidth),new Rectangle(newPoint.StartP, new Size(1, 1)));
  1082. break;
  1083. case ImageType.Line:
  1084. displayGraphics.DrawLine(new Pen(newColor,lineWidth),newPoint.StartP,newPoint.EndP);
  1085. break;
  1086. case ImageType.Circle:
  1087. displayGraphics.DrawLine(new Pen(newColor),newPoint.StartP,newPoint.EndP);
  1088. break;
  1089. case ImageType.FillCircle:
  1090. displayGraphics.DrawLine(new Pen(newColor),newPoint.StartP,newPoint.EndP);
  1091. break;
  1092. case ImageType.Rectangle:
  1093. displayGraphics.DrawRectangle(new Pen(newColor,lineWidth),newPoint.Rect);
  1094. break;
  1095. case ImageType.FillRectangle:
  1096. displayGraphics.FillRectangle(new SolidBrush(newColor),newPoint.Rect);
  1097. break;
  1098. case ImageType.Ellipse:
  1099. displayGraphics.DrawEllipse(new Pen(newColor,lineWidth),newPoint.Rect);
  1100. break;
  1101. case ImageType.FillEllipse:
  1102. displayGraphics.FillEllipse(new SolidBrush(newColor),newPoint.Rect);
  1103. break;
  1104. case ImageType.Path:
  1105. displayGraphics.DrawPath(new Pen(newColor,lineWidth), mousePath);
  1106. break;
  1107. case ImageType.Eraser:
  1108. displayGraphics.FillRegion(new SolidBrush(newColor), newRegion);
  1109. break;
  1110. case ImageType.Polygon:
  1111. tempPoint.DrawList(displayGraphics);
  1112. break;
  1113. case ImageType.Curve:
  1114. tempPoint.DrawList(displayGraphics);
  1115. break;
  1116. case ImageType.ClosedCurve:
  1117. tempPoint.DrawList(displayGraphics);
  1118. break;
  1119. case ImageType.Empty:
  1120. break;
  1121. case ImageType.Pick:
  1122. if(picked == true)
  1123. {
  1124. pointViewList.DrawList(displayGraphics);
  1125. if(changed == true&&drawImageType[regionIndex]!=(int)ImageType.Path)
  1126. {
  1127. if(drawImageType[regionIndex]==(int)ImageType.Rectangle)
  1128. {
  1129. displayGraphics.DrawRectangle(new Pen(newColor,lineWidth), tempChangePoint.Rect);
  1130. }
  1131. else if(drawImageType[regionIndex]==(int)ImageType.FillRectangle)
  1132. {
  1133. displayGraphics.FillRectangle(new SolidBrush(newColor), tempChangePoint.Rect);
  1134. }
  1135. else if(drawImageType[regionIndex]==(int)ImageType.Ellipse
  1136. ||drawImageType[regionIndex]==(int)ImageType.FillEllipse)
  1137. {
  1138. displayGraphics.DrawRectangle(new Pen(Color.Black,1), tempChangePoint.Rect);
  1139. }
  1140. }
  1141. }
  1142. break;
  1143. }
  1144. drawingList.DrawList(displayGraphics);
  1145. if(eraser == true)
  1146. notchangeList.DrawList(displayGraphics);
  1147. //g.Dispose();
  1148. }
  1149. private void Point2Region(Point[] p)
  1150. {
  1151. Point[] point = new Point[p.Length];
  1152. int j = 0;
  1153. foreach(Point newp in p)
  1154. {
  1155. point[j++]=newp;
  1156. }
  1157. tempRegion = new Region[p.Length];
  1158. for(int i=0;i<p.Length;i++)
  1159. {
  1160. point[i].Offset(-(int)(2*lineWidth),-(int)(2*lineWidth));
  1161. Rectangle r = new Rectangle(point[i],new Size((int)(4*lineWidth),(int)(4*lineWidth)));
  1162. Region rr = new Region(r);
  1163. tempRegion[i] = rr;
  1164. }
  1165. }
  1166. private void RegionMove(int index, int x, int y)
  1167. {
  1168. for(int i=0;i<pointArray[index].Length;i++)
  1169. {
  1170. pointArray[index][i].X = tempMovePoint[i].X + x;
  1171. pointArray[index][i].Y = tempMovePoint[i].Y + y;
  1172. }
  1173. }
  1174. private void PointView(int index)
  1175. {
  1176. Point tempPoint2;
  1177. foreach(Point tempPoint in pointArray[index])
  1178. {
  1179. tempPoint2 = tempPoint;
  1180. tempPoint.Offset(-(int)(2*lineWidth),-(int)(2*lineWidth));
  1181. tempPoint2.Offset((int)(2*lineWidth),(int)(2*lineWidth));
  1182. pointViewList.Add(new DHollowRectangle(new Point[]{tempPoint,tempPoint2},Color.DarkRed,1));
  1183. tempPoint.Offset((int)(2*lineWidth),(int)(2*lineWidth));
  1184. }
  1185. }
  1186. private void PointChange(int index)
  1187. {
  1188. Point tempPoint2;
  1189. for(int i=0;i<pointArray[index].Length;i++)
  1190. {
  1191. tempPoint2 = pointArray[index][i];
  1192. pointArray[index][i].Offset(-(int)(2*lineWidth),-(int)(2*lineWidth));
  1193. tempPoint2.Offset((int)(2*lineWidth),(int)(2*lineWidth));
  1194. pointViewList[i].pointchange(new Point[]{pointArray[index][i],tempPoint2});
  1195. pointArray[index][i].Offset((int)(2*lineWidth),(int)(2*lineWidth));
  1196. }
  1197. }
  1198. private void RegionChange(int index)
  1199. {
  1200. ImageType tempType = (ImageType)drawImageType[index];
  1201. switch(tempType)
  1202. {
  1203. case ImageType.Point:
  1204. regionCollection[index] = new Region(new Rectangle(pointArray[index][0], new Size((int)lineWidth*4, (int)lineWidth*4)));
  1205. break;
  1206. case ImageType.Line:
  1207. if(Math.Abs((float)(pointArray[index][0].Y-pointArray[index][1].Y)/(float)(pointArray[index][0].X-pointArray[index][1].X))<=1)
  1208. {
  1209. regionPath = new GraphicsPath(new Point[]{
  1210. new Point(pointArray[index][0].X,pointArray[index][0].Y-10),
  1211. new Point(pointArray[index][1].X,pointArray[index][1].Y-10),
  1212. new Point(pointArray[index][1].X,pointArray[index][1].Y+10),
  1213. new Point(pointArray[index][0].X,pointArray[index][0].Y+10),
  1214. new Point(pointArray[index][0].X,pointArray[index][0].Y-10)
  1215. },new byte[]{
  1216. (byte)PathPointType.Start,
  1217. (byte)PathPointType.Line,
  1218. (byte)PathPointType.Line,
  1219. (byte)PathPointType.Line,
  1220. (byte)PathPointType.Line
  1221. });
  1222. }
  1223. else
  1224. {
  1225. regionPath = new GraphicsPath(new Point[]{
  1226. new Point(pointArray[index][0].X-10,pointArray[index][0].Y),
  1227. new Point(pointArray[index][0].X+10,pointArray[index][0].Y),
  1228. new Point(pointArray[index][1].X+10,pointArray[index][1].Y),
  1229. new Point(pointArray[index][1].X-10,pointArray[index][1].Y),
  1230. new Point(pointArray[index][0].X-10,pointArray[index][0].Y)
  1231. },new byte[]{
  1232. (byte)PathPointType.Start,
  1233. (byte)PathPointType.Line,
  1234. (byte)PathPointType.Line,
  1235. (byte)PathPointType.Line,
  1236. (byte)PathPointType.Line
  1237. });
  1238. }
  1239. regionPath.CloseFigure();
  1240. regionCollection[index] = new Region(regionPath);
  1241. break;
  1242. case ImageType.Circle:
  1243. case ImageType.FillCircle:
  1244. Distance = (int)Math.Sqrt (Math.Pow((pointArray[index][0].X-pointArray[index][1].X),2.0)+Math.Pow((pointArray[index][0].Y-pointArray[index][1].Y),2.0));
  1245. pointArray[index][0].Offset(-Distance,-Distance);
  1246. diameter = Distance*2;
  1247. regionCollection[index] = new Region(new Rectangle(pointArray[index][0], new Size(diameter, diameter)));
  1248. pointArray[index][0].Offset(Distance,Distance);
  1249. break;
  1250. case ImageType.Polygon:
  1251. case ImageType.Curve:
  1252. case ImageType.ClosedCurve:
  1253. byte[] tempByte = new byte[pointArray[index].Length];
  1254. for(int i=0;i<pointArray[index].Length;i++)
  1255. {
  1256. if(i==0)
  1257. tempByte[i] = (byte)PathPointType.Start;
  1258. else
  1259. tempByte[i] = (byte)PathPointType.Line;
  1260. }
  1261. regionPath = new GraphicsPath(pointArray[index], tempByte);
  1262. regionPath.CloseFigure();
  1263. regionCollection[index] = new Region(regionPath);
  1264. break;
  1265. case ImageType.Text:
  1266. break;
  1267. }
  1268. }
  1269. #endregion
  1270. #region 画图框按钮
  1271. /// <summary>
  1272. /// 图画图按钮框事件
  1273. /// </summary>
  1274. private void AddPoint_Click(object sender, System.EventArgs e)
  1275. {
  1276. this.statusBar.Panels[0].Text = "Point";
  1277. newType = ImageType.Point;
  1278. }
  1279. private void AddLine_Click(object sender, System.EventArgs e)
  1280. {
  1281. this.statusBar.Panels[0].Text = "Line";
  1282. newType = ImageType.Line;
  1283. }
  1284. private void AddCircle_Click(object sender, System.EventArgs e)
  1285. {
  1286. this.statusBar.Panels[0].Text = "Circle";
  1287. newType = ImageType.Circle;
  1288. }
  1289. private void AddFillCircle_Click(object sender, System.EventArgs e)
  1290. {
  1291. this.statusBar.Panels[0].Text = "FillCircle";
  1292. newType = ImageType.FillCircle;
  1293. }
  1294. private void AddHollowEllipse_Click(object sender, System.EventArgs e)
  1295. {
  1296. this.statusBar.Panels[0].Text = "Ellipse";
  1297. newType = ImageType.Ellipse;
  1298. }
  1299. private void AddHollowRectangle_Click(object sender, System.EventArgs e)
  1300. {
  1301. this.statusBar.Panels[0].Text = "Rectangle";
  1302. newType = ImageType.Rectangle;
  1303. }
  1304. private void AddFilledEllipse_Click(object sender, System.EventArgs e)
  1305. {
  1306. this.statusBar.Panels[0].Text = "FillEllipse";
  1307. newType = ImageType.FillEllipse;
  1308. }
  1309. private void AddFilledRectangle_Click(object sender, System.EventArgs e)
  1310. {
  1311. this.statusBar.Panels[0].Text = "FillRectangle";
  1312. newType = ImageType.FillRectangle;
  1313. }
  1314. private void AddPath_Click(object sender, System.EventArgs e)
  1315. {
  1316. this.statusBar.Panels[0].Text = "Path";
  1317. newType = ImageType.Path;
  1318. }
  1319. private void btnEraser_Click(object sender, System.EventArgs e)
  1320. {
  1321. this.statusBar.Panels[0].Text = "Eraser";
  1322. newType = ImageType.Eraser;
  1323. EraserSize = 2;
  1324. }
  1325. private void btnText_Click(object sender, System.EventArgs e)
  1326. {
  1327. this.statusBar.Panels[0].Text = "Text";
  1328. newType = ImageType.Text;
  1329. MakeForm();
  1330. }
  1331. private void btnCircleAt_Click(object sender, System.EventArgs e)
  1332. {
  1333. this.statusBar.Panels[0].Text = "CircleAt";
  1334. newType = ImageType.CircleAt;
  1335. MakeCircleAt();
  1336. }
  1337. private void AddPolygon_Click(object sender, System.EventArgs e)
  1338. {
  1339. this.statusBar.Panels[0].Text = "Polygon";
  1340. newType = ImageType.Polygon;
  1341. }
  1342. private void Curve_Click(object sender, System.EventArgs e)
  1343. {
  1344. this.statusBar.Panels[0].Text = "Curve";
  1345. newType = ImageType.Curve;
  1346. }
  1347. private void ClosedCurve_Click(object sender, System.EventArgs e)
  1348. {
  1349. this.statusBar.Panels[0].Text = "ClosedCurve";
  1350. newType = ImageType.ClosedCurve;
  1351. }
  1352. private void btnPick_Click(object sender, System.EventArgs e)
  1353. {
  1354. this.statusBar.Panels[0].Text = "PickUp";
  1355. newType = ImageType.Pick;
  1356. }
  1357. private void Change_Click(object sender, System.EventArgs e)
  1358. {
  1359. if(drawingList.Count==0)
  1360. return;
  1361. picked = false;
  1362. drawingListUndo.Add(drawingList[drawingList.Count-1]);
  1363. drawingList.RemoveAt(drawingList.Count-1);
  1364. regionCollectionUndo.Add(regionCollection[regionCollection.Count-1]);
  1365. regionCollection.RemoveAt(regionCollection.Count-1);
  1366. pointArrayUndo.Add(pointArray[pointArray.Count-1]);
  1367. pointArray.RemoveAt(pointArray.Count-1);
  1368. regionArrayCollectionUndo.Add(regionArrayCollection[regionArrayCollection.Count-1]);
  1369. regionArrayCollection.RemoveAt(regionArrayCollection.Count-1);
  1370. drawImageTypeUndo.Add((ImageType)drawImageType[drawImageType.Count-1]);
  1371. drawImageType.RemoveAt(drawImageType.Count-1);
  1372. newType = ImageType.Empty;
  1373. Drawing.Invalidate();
  1374. }
  1375. private void NotChange_Click(object sender, System.EventArgs e)
  1376. {
  1377. if(notchangeList.Count==0)
  1378. return;
  1379. notchangeListUndo.Add(notchangeList[notchangeList.Count-1]);
  1380. notchangeList.RemoveAt(notchangeList.Count-1);
  1381. Drawing.Invalidate();
  1382. }
  1383. private void Change2_Click(object sender, System.EventArgs e)
  1384. {
  1385. if(drawingListUndo.Count==0)
  1386. return;
  1387. picked = false;
  1388. drawingList.Add(drawingListUndo[drawingListUndo.Count-1]);
  1389. drawingListUndo.RemoveAt(drawingListUndo.Count-1);
  1390. regionCollection.Add(regionCollectionUndo[regionCollectionUndo.Count-1]);
  1391. regionCollectionUndo.RemoveAt(regionCollectionUndo.Count-1);
  1392. pointArray.Add(pointArrayUndo[pointArrayUndo.Count-1]);
  1393. pointArrayUndo.RemoveAt(pointArrayUndo.Count-1);
  1394. regionArrayCollection.Add(regionArrayCollectionUndo[regionArrayCollectionUndo.Count-1]);
  1395. regionArrayCollectionUndo.RemoveAt(regionArrayCollectionUndo.Count-1);
  1396. drawImageType.Add((ImageType)drawImageTypeUndo[drawImageTypeUndo.Count-1]);
  1397. drawImageTypeUndo.RemoveAt(drawImageTypeUndo.Count-1);
  1398. Drawing.Invalidate();
  1399. }
  1400. private void NotChange2_Click(object sender, System.EventArgs e)
  1401. {
  1402. if(notchangeListUndo.Count==0)
  1403. return;
  1404. notchangeList.Add(notchangeListUndo[notchangeListUndo.Count-1]);
  1405. notchangeListUndo.RemoveAt(notchangeListUndo.Count-1);
  1406. Drawing.Invalidate();
  1407. }
  1408. #endregion
  1409. #region 鼠标事件
  1410. /// <summary>
  1411. /// 鼠标事件
  1412. /// </summary>
  1413. private void Drawing_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  1414. {
  1415. if (e.Button != MouseButtons.Left)
  1416. return;
  1417. newPoint = new MousePoint(e.X, e.Y);
  1418. switch(newType)
  1419. {
  1420. case ImageType.Path:
  1421. mousePath = new GraphicsPath();
  1422. mousePath.AddLine(e.X,e.Y,e.X,e.Y);
  1423. break;
  1424. case ImageType.Eraser:
  1425. eraser = true;
  1426. newPoint.EndX = e.X;
  1427. newPoint.EndY = e.Y;
  1428. Point p = newPoint.StartP;
  1429. p.Offset(-2,-2);
  1430. newRegion = new Region(new Rectangle(p, new Size(4,4)));
  1431. break;
  1432. case ImageType.Text:
  1433. newForm.Show();
  1434. break;
  1435. case ImageType.Polygon:
  1436. pointCollection.Add(newPoint.StartP);
  1437. tempPoint.Add(new DPoint(new Point[1]{newPoint.StartP}, newColor,lineWidth));
  1438. Drawing.Invalidate();
  1439. break;
  1440. case ImageType.Curve:
  1441. pointCollection.Add(newPoint.StartP);
  1442. tempPoint.Add(new DPoint(new Point[1]{newPoint.StartP}, newColor,lineWidth));
  1443. Drawing.Invalidate();
  1444. break;
  1445. case ImageType.ClosedCurve:
  1446. pointCollection.Add(newPoint.StartP);
  1447. tempPoint.Add(new DPoint(new Point[1]{newPoint.StartP}, newColor,lineWidth));
  1448. Drawing.Invalidate();
  1449. break;
  1450. case ImageType.Pick:
  1451. if(picked == true)
  1452. {
  1453. for(int k=0;k<regionArrayCollection[regionIndex].Length;k++)
  1454. {
  1455. if(regionArrayCollection[regionIndex][k].IsVisible(newPoint.StartP))
  1456. {
  1457. pointIndex = k;
  1458. changed = true;
  1459. break;
  1460. }
  1461. else
  1462. changed = false;
  1463. }
  1464. if(changed == true)
  1465. break;
  1466. }
  1467. int m = regionIndex;
  1468. if(picked == true)
  1469. m = (regionIndex+1)%regionCollection.Count; //循环下一项开始
  1470. int n = 0;
  1471. for(;n<regionCollection.Count;n++)
  1472. {
  1473. if(m >= regionCollection.Count)
  1474. m = 0;
  1475. if(regionCollection[m++].IsVisible(newPoint.StartP))
  1476. {
  1477. pointViewList = new DShapeList();
  1478. regionIndex = m-1;
  1479. tempMovePoint = new Point[pointArray[regionIndex].Length];
  1480. for(int j=0;j<pointArray[regionIndex].Length;j++)
  1481. {
  1482. tempMovePoint[j] = pointArray[regionIndex][j];
  1483. }
  1484. PointView(regionIndex);
  1485. Drawing.Invalidate();
  1486. picked = true;
  1487. if(drawImageType[regionIndex]==(int)ImageType.Path)
  1488. {
  1489. mousePath = drawingList[regionIndex].pathChange(mousePath,true);
  1490. }
  1491. changed = false;
  1492. break;
  1493. }
  1494. else
  1495. {
  1496. pointViewList = new DShapeList();
  1497. Drawing.Invalidate();
  1498. picked = false;
  1499. }
  1500. }
  1501. break;
  1502. }
  1503. }
  1504. private void Drawing_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
  1505. {
  1506. if (e.Button != MouseButtons.Left)
  1507. return;
  1508. newPoint.EndX = e.X;
  1509. newPoint.EndY = e.Y;
  1510. this.statusBar.Panels[1].Text="Point:"+e.X.ToString() + "," + e.Y.ToString();
  1511. switch(newType)
  1512. {
  1513. case ImageType.Path:
  1514. mousePath.AddLine(e.X,e.Y,e.X,e.Y);
  1515. break;
  1516. case ImageType.Eraser:
  1517. Point p = newPoint.EndP;
  1518. p.Offset(-EraserSize,-EraserSize);
  1519. newRegion = new Region(new Rectangle(p, new Size(EraserSize*2,EraserSize*2)));
  1520. notchangeList.Add(new DEraser(newPoint.EndP, newColor, EraserSize));
  1521. break;
  1522. case ImageType.Pick:
  1523. if(picked == true&&changed !=true)
  1524. {
  1525. mouseMove = true;
  1526. int MoveX = newPoint.EndP.X-newPoint.StartP.X;
  1527. int MoveY = newPoint.EndP.Y-newPoint.StartP.Y;
  1528. RegionMove(regionIndex, MoveX,MoveY);
  1529. if(drawImageType[regionIndex]!=(int)ImageType.Path)
  1530. {
  1531. drawingList[regionIndex].pointchange(pointArray[regionIndex]);
  1532. }
  1533. else
  1534. {
  1535. regionPath = (GraphicsPath)mousePath.Clone();
  1536. Matrix translateMatrix = new Matrix();
  1537. translateMatrix.Translate(MoveX, MoveY);
  1538. regionPath.Transform(translateMatrix);
  1539. drawingList[regionIndex].pathChange(regionPath,false);
  1540. }
  1541. PointChange(regionIndex);
  1542. }
  1543. if(changed ==true&&drawImageType[regionIndex]!=(int)ImageType.Path)
  1544. {
  1545. mouseMove = true;
  1546. pointArray[regionIndex][pointIndex] = newPoint.EndP;
  1547. if(drawImageType[regionIndex]==(int)ImageType.Rectangle
  1548. ||drawImageType[regionIndex]==(int)ImageType.FillRectangle
  1549. ||drawImageType[regionIndex]==(int)ImageType.Ellipse
  1550. ||drawImageType[regionIndex]==(int)ImageType.FillEllipse)
  1551. {
  1552. tempChangePoint = new MousePoint(pointArray[regionIndex][1-pointIndex].X, pointArray[regionIndex][1-pointIndex].Y);
  1553. tempChangePoint.EndX = pointArray[regionIndex][pointIndex].X;
  1554. tempChangePoint.EndY = pointArray[regionIndex][pointIndex].Y;
  1555. regionCollection[regionIndex] = new Region(tempChangePoint.Rect);
  1556. }
  1557. drawingList[regionIndex].pointchange(pointArray[regionIndex]);
  1558. PointChange(regionIndex);
  1559. }
  1560. break;
  1561. }
  1562. Drawing.Invalidate();
  1563. }
  1564. private void Drawing_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
  1565. {
  1566. switch(newType)
  1567. {
  1568. case ImageType.Point:
  1569. //加顶点
  1570. tempPointArray = new Point[1]{newPoint.StartP};
  1571. pointArray.Add(tempPointArray);
  1572. //加顶点区域
  1573. Point2Region(tempPointArray);
  1574. regionArrayCollection.Add(tempRegion);
  1575. //加图元区域
  1576. newPoint.StartP.Offset(-2,-2);
  1577. regionCollection.Add(new Region(new Rectangle(newPoint.StartP, new Size((int)lineWidth*4, (int)lineWidth*4))));
  1578. drawImageType.Add(ImageType.Point);
  1579. //加图元
  1580. drawingList.Add(new DPoint(tempPointArray,newColor,lineWidth));
  1581. break;
  1582. case ImageType.Line:
  1583. //加顶点
  1584. tempPointArray = new Point[2]{newPoint.StartP,newPoint.EndP};
  1585. pointArray.Add(tempPointArray);
  1586. //加顶点区域
  1587. Point2Region(tempPointArray);
  1588. regionArrayCollection.Add(tempRegion);
  1589. //加图元区域
  1590. if(Math.Abs((float)(newPoint.StartP.Y-newPoint.EndP.Y)/(float)(newPoint.StartP.X-newPoint.EndP.X))<=1)
  1591. {
  1592. regionPath = new GraphicsPath(new Point[]{
  1593. new Point(newPoint.StartP.X,newPoint.StartP.Y-10),
  1594. new Point(newPoint.EndP.X,newPoint.StartP.Y-10),
  1595. new Point(newPoint.EndP.X,newPoint.EndP.Y+10),
  1596. new Point(newPoint.StartP.X,newPoint.EndP.Y+10),
  1597. new Point(newPoint.StartP.X,newPoint.StartP.Y-10)
  1598. },new byte[]{
  1599. (byte)PathPointType.Start,
  1600. (byte)PathPointType.Line,
  1601. (byte)PathPointType.Line,
  1602. (byte)PathPointType.Line,
  1603. (byte)PathPointType.Line
  1604. });
  1605. }
  1606. else
  1607. {
  1608. regionPath = new GraphicsPath(new Point[]{
  1609. new Point(newPoint.StartP.X-10,newPoint.StartP.Y),
  1610. new Point(newPoint.StartP.X+10,newPoint.StartP.Y),
  1611. new Point(newPoint.EndP.X+10,newPoint.EndP.Y),
  1612. new Point(newPoint.EndP.X-10,newPoint.EndP.Y),
  1613. new Point(newPoint.StartP.X-10,newPoint.StartP.Y)
  1614. },new byte[]{
  1615. (byte)PathPointType.Start,
  1616. (byte)PathPointType.Line,
  1617. (byte)PathPointType.Line,
  1618. (byte)PathPointType.Line,
  1619. (byte)PathPointType.Line
  1620. });
  1621. }
  1622. regionPath.CloseFigure();
  1623. regionCollection.Add(new Region(regionPath));
  1624. drawImageType.Add(ImageType.Line);
  1625. //加图元
  1626. drawingList.Add(new DLine(tempPointArray,newColor,lineWidth));
  1627. break;
  1628. case ImageType.Circle:
  1629. //加顶点
  1630. tempPointArray = new Point[2]{newPoint.StartP, newPoint.EndP};
  1631. pointArray.Add(tempPointArray);
  1632. //加图元
  1633. drawingList.Add(new DHollowCircle(tempPointArray, newColor,lineWidth));
  1634. //加顶点区域
  1635. Point2Region(tempPointArray);
  1636. regionArrayCollection.Add(tempRegion);
  1637. //加图元区域
  1638. Distance = (int)Math.Sqrt (Math.Pow((tempPointArray[0].X-tempPointArray[1].X),2.0)+Math.Pow((tempPointArray[0].Y-tempPointArray[1].Y),2.0));
  1639. tempPointArray[0].Offset(-Distance,-Distance);
  1640. diameter = Distance*2;
  1641. regionCollection.Add(new Region(new Rectangle(tempPointArray[0], new Size(diameter, diameter))));
  1642. tempPointArray[0].Offset(Distance,Distance);//指针乃万恶之首
  1643. drawImageType.Add(ImageType.Circle);
  1644. break;
  1645. case ImageType.FillCircle:
  1646. tempPointArray = new Point[2]{newPoint.StartP, newPoint.EndP};
  1647. pointArray.Add(tempPointArray);
  1648. drawingList.Add(new DFilledCircle(tempPointArray, newColor,lineWidth, newColor));
  1649. Point2Region(tempPointArray);
  1650. regionArrayCollection.Add(tempRegion);
  1651. Distance = (int)Math.Sqrt (Math.Pow((tempPointArray[0].X-tempPointArray[1].X),2.0)+Math.Pow((tempPointArray[0].Y-tempPointArray[1].Y),2.0));
  1652. tempPointArray[0].Offset(-Distance,-Distance);
  1653. diameter = Distance*2;
  1654. regionCollection.Add(new Region(new Rectangle(tempPointArray[0], new Size(diameter, diameter))));
  1655. tempPointArray[0].Offset(Distance,Distance);
  1656. drawImageType.Add(ImageType.FillCircle);
  1657. break;
  1658. case ImageType.Rectangle:
  1659. regionCollection.Add(new Region(newPoint.Rect)); //一定要先调用Rect,改变起点、终点
  1660. drawImageType.Add(ImageType.Rectangle);
  1661. tempPointArray = new Point[2]{newPoint.StartP, newPoint.EndP};
  1662. pointArray.Add(tempPointArray);
  1663. Point2Region(tempPointArray);
  1664. regionArrayCollection.Add(tempRegion);
  1665. drawingList.Add(new DHollowRectangle(tempPointArray, newColor,lineWidth));
  1666. break;
  1667. case ImageType.FillRectangle:
  1668. regionCollection.Add(new Region(newPoint.Rect));
  1669. drawImageType.Add(ImageType.FillRectangle);
  1670. tempPointArray = new Point[2]{newPoint.StartP, newPoint.EndP};
  1671. pointArray.Add(tempPointArray);
  1672. Point2Region(tempPointArray);
  1673. regionArrayCollection.Add(tempRegion);
  1674. drawingList.Add(new DFilledRectangle(tempPointArray, newColor,lineWidth, newColor));
  1675. break;
  1676. case ImageType.Ellipse:
  1677. regionCollection.Add(new Region(newPoint.Rect));
  1678. drawImageType.Add(ImageType.Ellipse);
  1679. tempPointArray = new Point[2]{newPoint.StartP, newPoint.EndP};
  1680. pointArray.Add(tempPointArray);
  1681. Point2Region(tempPointArray);
  1682. regionArrayCollection.Add(tempRegion);
  1683. drawingList.Add(new DHollowEllipse(tempPointArray, newColor,lineWidth));
  1684. break;
  1685. case ImageType.FillEllipse:
  1686. regionCollection.Add(new Region(newPoint.Rect));
  1687. drawImageType.Add(ImageType.FillEllipse);
  1688. tempPointArray = new Point[2]{newPoint.StartP, newPoint.EndP};
  1689. pointArray.Add(tempPointArray);
  1690. Point2Region(tempPointArray);
  1691. regionArrayCollection.Add(tempRegion);
  1692. drawingList.Add(new DFilledEllipse(tempPointArray, newColor,lineWidth, newColor));
  1693. break;
  1694. case ImageType.Path:
  1695. drawingList.Add(new DPath(mousePath, newColor,lineWidth));
  1696. tempPointArray = new Point[1]{newPoint.StartP};
  1697. pointArray.Add(tempPointArray);
  1698. Point2Region(tempPointArray);
  1699. regionArrayCollection.Add(tempRegion);
  1700. regionPath = (GraphicsPath)mousePath.Clone();
  1701. regionPath.CloseFigure();
  1702. regionCollection.Add(new Region(regionPath));
  1703. drawImageType.Add(ImageType.Path);
  1704. break;
  1705. case ImageType.Pick:
  1706. if(picked == true&&mouseMove == true&&changed!=true)
  1707. {
  1708. int MoveX = newPoint.EndP.X-newPoint.StartP.X;
  1709. int MoveY = newPoint.EndP.Y-newPoint.StartP.Y;
  1710. regionCollection[regionIndex].Translate(MoveX, MoveY);
  1711. foreach(Region r in regionArrayCollection[regionIndex])
  1712. {
  1713. r.Translate(MoveX, MoveY);
  1714. }
  1715. if(drawImageType[regionIndex]==(int)ImageType.Path)
  1716. {
  1717. Matrix translateMatrix = new Matrix();
  1718. translateMatrix.Translate(MoveX, MoveY);
  1719. mousePath.Transform(translateMatrix);
  1720. drawingList[regionIndex].pathChange(mousePath,false);
  1721. }
  1722. }
  1723. if(changed == true&&mouseMove == true&&drawImageType[regionIndex]!=(int)ImageType.Path)
  1724. {
  1725. int MoveX = newPoint.EndP.X-newPoint.StartP.X;
  1726. int MoveY = newPoint.EndP.Y-newPoint.StartP.Y;
  1727. regionArrayCollection[regionIndex][pointIndex].Translate(MoveX,MoveY);
  1728. RegionChange(regionIndex);
  1729. if(drawImageType[regionIndex]==(int)ImageType.Rectangle
  1730. ||drawImageType[regionIndex]==(int)ImageType.FillRectangle
  1731. ||drawImageType[regionIndex]==(int)ImageType.Ellipse
  1732. ||drawImageType[regionIndex]==(int)ImageType.FillEllipse)
  1733. {
  1734. pointArray[regionIndex][0] = tempChangePoint.StartP;
  1735. pointArray[regionIndex][1] = tempChangePoint.EndP;
  1736. drawingList[regionIndex].pointchange(pointArray[regionIndex]);
  1737. Point2Region(pointArray[regionIndex]);
  1738. regionArrayCollection[regionIndex] = tempRegion;
  1739. }
  1740. }
  1741. mouseMove = false;
  1742. break;
  1743. }
  1744. Drawing.Invalidate();
  1745. }
  1746. private void Drawing_MouseEnter(object sender, System.EventArgs e)
  1747. {
  1748. if(newType != ImageType.Eraser&&newType != ImageType.Pick)
  1749. this.Cursor = System.Windows.Forms.Cursors.Cross;
  1750. else
  1751. this.Cursor = System.Windows.Forms.Cursors.Default;
  1752. }
  1753. private void Drawing_MouseLeave(object sender, System.EventArgs e)
  1754. {
  1755. this.Cursor = System.Windows.Forms.Cursors.Default;
  1756. }
  1757. #endregion
  1758. #region 右键功能
  1759. /// <summary>
  1760. /// 右键功能。
  1761. /// </summary>
  1762. private void menuItemSize1_Click(object sender, System.EventArgs e)
  1763. {
  1764. EraserSize = 2;
  1765. }
  1766. private void menuItemmenuItemSize2_Click(object sender, System.EventArgs e)
  1767. {
  1768. EraserSize = 4;
  1769. }
  1770. private void menuItemSize3_Click(object sender, System.EventArgs e)
  1771. {
  1772. EraserSize = 6;
  1773. }
  1774. private void menuItemCA_Click(object sender, System.EventArgs e)
  1775. {
  1776. newCircle.Show();
  1777. }
  1778. private void menuItemClose_Click(object sender, System.EventArgs e)
  1779. {
  1780. if(pointCollection.Count==0)
  1781. return;
  1782. tempPointArray = new Point[pointCollection.Count];
  1783. byte[] tempByte = new byte[pointCollection.Count];
  1784. int i = 0;
  1785. foreach(Point newP in pointCollection)
  1786. {
  1787. tempPointArray[i] = newP;
  1788. if(i==0)
  1789. tempByte[i++] = (byte)PathPointType.Start;
  1790. else
  1791. tempByte[i++] = (byte)PathPointType.Line;
  1792. }
  1793. pointArray.Add(tempPointArray);
  1794. Point2Region(tempPointArray);
  1795. regionArrayCollection.Add(tempRegion);
  1796. regionPath = new GraphicsPath(tempPointArray, tempByte);
  1797. regionPath.CloseFigure();
  1798. regionCollection.Add(new Region(regionPath));
  1799. switch(newType)
  1800. {
  1801. case ImageType.Polygon:
  1802. drawingList.Add(new DPolygon(tempPointArray, newColor,lineWidth));
  1803. drawImageType.Add(ImageType.Polygon);
  1804. break;
  1805. case ImageType.Curve:
  1806. drawingList.Add(new DCurve(tempPointArray, newColor,lineWidth));
  1807. drawImageType.Add(ImageType.Curve);
  1808. break;
  1809. case ImageType.ClosedCurve:
  1810. drawingList.Add(new DClosedCurve(tempPointArray, newColor,lineWidth));
  1811. drawImageType.Add(ImageType.ClosedCurve);
  1812. break;
  1813. }
  1814. Drawing.Invalidate();
  1815. pointCollection.RemoveRange(0,pointCollection.Count);
  1816. tempPoint = new DShapeList();
  1817. }
  1818. private void menuItemLw_Click(object sender, System.EventArgs e)
  1819. {
  1820. tempType = newType;
  1821. newType = ImageType.Set;
  1822. newForm.Show();
  1823. MakeForm();
  1824. }
  1825. #endregion
  1826. #region 窗口事件
  1827. /// <summary>
  1828. /// 窗口事件。
  1829. /// </summary>
  1830. private void MakeForm()
  1831. {
  1832. newForm.VisibleChanged += new EventHandler(newForm_VisibleChanged);
  1833. }
  1834. private void MakeCircleAt()
  1835. {
  1836. newCircle.VisibleChanged +=new EventHandler(newCircle_VisibleChanged);
  1837. }
  1838. private void newForm_VisibleChanged(object sender, System.EventArgs e)
  1839. {
  1840. if(newForm.Visible == false)
  1841. {
  1842. switch(newType)
  1843. {
  1844. case ImageType.Text:
  1845. if(newForm.cancle ==false)
  1846. {
  1847. eraser = true;
  1848. notchangeList.Add(new DText(new Point[]{newPoint.StartP}, newColor, newForm.outText, newForm.txtSize,newForm.TxtFont));
  1849. Drawing.Invalidate();
  1850. }
  1851. break;
  1852. case ImageType.Set:
  1853. if(newForm.cancle == false)
  1854. {
  1855. lineWidth = Convert.ToSingle(newForm.outText);
  1856. newType = tempType;
  1857. }
  1858. break;
  1859. }
  1860. }
  1861. }
  1862. private void newCircle_VisibleChanged(object sender, System.EventArgs e)
  1863. {
  1864. if(newCircle.Visible == false)
  1865. {
  1866. if(newForm.cancle ==false)
  1867. {
  1868. tempPointArray = new Point[2]{newCircle.startP, newCircle.endP};
  1869. pointArray.Add(tempPointArray);
  1870. Point2Region(tempPointArray);
  1871. regionArrayCollection.Add(tempRegion);
  1872. Distance = (int)Math.Sqrt (Math.Pow((tempPointArray[0].X-tempPointArray[1].X),2.0)+Math.Pow((tempPointArray[0].Y-tempPointArray[1].Y),2.0));
  1873. tempPointArray[0].Offset(-Distance,-Distance);
  1874. diameter = Distance*2;
  1875. regionCollection.Add(new Region(new Rectangle(tempPointArray[0], new Size(diameter, diameter))));
  1876. drawingList.Add(new DArc(tempPointArray, newColor,lineWidth,newCircle.FirstAngle,newCircle.EndAngle));
  1877. drawImageType.Add(ImageType.Circle);
  1878. Drawing.Invalidate();
  1879. }
  1880. }
  1881. }
  1882. private void menuBeziers_Click(object sender, System.EventArgs e)
  1883. {
  1884. Example newWindow = new Example();
  1885. newWindow.Show();
  1886. }
  1887. #endregion
  1888. #region 主菜单选项
  1889. /// <summary>
  1890. /// 图形存储集合等。
  1891. /// </summary>
  1892. private void menuNew_Click(object sender, System.EventArgs e)
  1893. {
  1894. drawingList = new DShapeList();
  1895. drawingListUndo = new DShapeList();
  1896. tempPoint = new DShapeList();
  1897. pointViewList = new DShapeList();
  1898. notchangeList = new DShapeList();
  1899. notchangeListUndo = new DShapeList();
  1900. newForm = new NewForm();
  1901. newCircle = new CircleForm();
  1902. pointCollection = new ArrayList();
  1903. regionCollection = new NewRegion();
  1904. regionCollectionUndo = new NewRegion();
  1905. pointArray = new PointArrayCollection();
  1906. pointArrayUndo = new PointArrayCollection();
  1907. regionArrayCollection = new NewRegionArray();
  1908. regionArrayCollectionUndo = new NewRegionArray();
  1909. drawImageType = new Type();
  1910. drawImageTypeUndo = new Type();
  1911. newType = ImageType.Empty;
  1912. picked = false;
  1913. changed = false;
  1914. mouseMove = false;
  1915. eraser = false;
  1916. regionIndex = 0;
  1917. Drawing.Invalidate();
  1918. fileName = "NewFile";
  1919. SetFormTitle();
  1920. }
  1921. private void menuOpen_Click(object sender, System.EventArgs e)
  1922. {
  1923. if(openFileDialog.ShowDialog() == DialogResult.OK)
  1924. {
  1925. fileName = openFileDialog.FileName;
  1926. try
  1927. {
  1928. FileStream newStream = (FileStream)openFileDialog.OpenFile();
  1929. newImage = new Bitmap(newStream);
  1930. drawingList = new DShapeList();
  1931. newType = ImageType.Empty;
  1932. Point p = new Point(0,0);
  1933. notchangeList.Add(new DImage(p,newImage));
  1934. eraser = true;
  1935. Drawing.Invalidate();
  1936. newStream.Close();
  1937. SetFormTitle();
  1938. }
  1939. catch(IOException err)
  1940. {
  1941. MessageBox.Show(err.Message,"myPGS",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
  1942. }
  1943. }
  1944. }
  1945. private void menuSave_Click(object sender, System.EventArgs e)
  1946. {
  1947. if(fileName=="NewFile")
  1948. {
  1949. menuSaveAs_Click(sender,e);
  1950. }
  1951. else
  1952. {
  1953. SaveFile();
  1954. }
  1955. }
  1956. private void menuSaveAs_Click(object sender, System.EventArgs e)
  1957. {
  1958. if(saveFileDialog.ShowDialog() == DialogResult.OK)
  1959. {
  1960. fileName =saveFileDialog.FileName;
  1961. SaveFile();
  1962. SetFormTitle();
  1963. }
  1964. }
  1965. protected void SaveFile()
  1966. {
  1967. try
  1968. {
  1969. FileStream newfile = (FileStream)saveFileDialog.OpenFile();
  1970. Point p = new Point(0,0);
  1971. int width;
  1972. int heigh;
  1973. width = Drawing.Width;
  1974. heigh = Drawing.Height;
  1975. Rectangle r= new Rectangle(p,new Size(width,heigh));
  1976. Image i = new Bitmap(width, heigh);
  1977. Graphics g = Graphics.FromImage(i);
  1978. g.FillRectangle(new SolidBrush(Color.White),r);
  1979. if(eraser == true)
  1980. notchangeList.DrawList(g);
  1981. drawingList.DrawList(g);
  1982. newImage = i;
  1983. if(fileName != "")
  1984. {
  1985. switch(saveFileDialog.FilterIndex)
  1986. {
  1987. case 1:
  1988. newImage.Save(newfile,System.Drawing.Imaging.ImageFormat.Jpeg);
  1989. break;
  1990. case 2:
  1991. newImage.Save(newfile,System.Drawing.Imaging.ImageFormat.Bmp);
  1992. break;
  1993. case 3:
  1994. newImage.Save(newfile,System.Drawing.Imaging.ImageFormat.Gif);
  1995. break;
  1996. default:
  1997. newImage.Save(newfile,System.Drawing.Imaging.ImageFormat.Bmp);
  1998. break;
  1999. }
  2000. }
  2001. newfile.Close();
  2002. }
  2003. catch(IOException err)
  2004. {
  2005. MessageBox.Show(err.Message,"myPGS",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
  2006. }
  2007. }
  2008. private void menuExit_Click(object sender, System.EventArgs e)
  2009. {
  2010. Application.Exit();
  2011. }
  2012. protected void SetFormTitle()
  2013. {
  2014. FileInfo fileinfo = new FileInfo(fileName);
  2015. this.Text = fileinfo.Name + " - myPGS";
  2016. }
  2017. private void Report_Click(object sender, System.EventArgs e)
  2018. {
  2019. System.Diagnostics.Process.Start("/CodeCommentReport/Solution_GraphicalCS.HTM");
  2020. }
  2021. private void Help_Click(object sender, System.EventArgs e)
  2022. {
  2023. System.Diagnostics.Process.Start("pgsHELP.hlp");
  2024. }
  2025. private void About_Click(object sender, System.EventArgs e)
  2026. {
  2027. About about = new About();
  2028. about.Show();
  2029. }
  2030. #endregion
  2031. #region 颜色
  2032. /// <summary>
  2033. /// 颜色。
  2034. /// </summary>
  2035. private void Black_Click(object sender, System.EventArgs e)
  2036. {
  2037. this.btnColor.BackColor = this.Black.BackColor;
  2038. newColor = this.Black.BackColor;
  2039. }
  2040. private void White_Click(object sender, System.EventArgs e)
  2041. {
  2042. this.btnColor.BackColor = this.White.BackColor;
  2043. newColor = this.White.BackColor;
  2044. }
  2045. private void Red_Click(object sender, System.EventArgs e)
  2046. {
  2047. this.btnColor.BackColor = this.Red.BackColor;
  2048. newColor = this.Red.BackColor;
  2049. }
  2050. private void blue_Click(object sender, System.EventArgs e)
  2051. {
  2052. this.btnColor.BackColor = this.blue.BackColor;
  2053. newColor = this.blue.BackColor;
  2054. }
  2055. private void Yellow_Click(object sender, System.EventArgs e)
  2056. {
  2057. this.btnColor.BackColor = this.Yellow.BackColor;
  2058. newColor = this.Yellow.BackColor;
  2059. }
  2060. private void LawnGreen_Click(object sender, System.EventArgs e)
  2061. {
  2062. this.btnColor.BackColor = this.LawnGreen.BackColor;
  2063. newColor = this.LawnGreen.BackColor;
  2064. }
  2065. private void Cyan_Click(object sender, System.EventArgs e)
  2066. {
  2067. this.btnColor.BackColor = this.Cyan.BackColor;
  2068. newColor = this.Cyan.BackColor;
  2069. }
  2070. private void Magenta_Click(object sender, System.EventArgs e)
  2071. {
  2072. this.btnColor.BackColor = this.Magenta.BackColor;
  2073. newColor = this.Magenta.BackColor;
  2074. }
  2075. private void MoreColor_Click(object sender, System.EventArgs e)
  2076. {
  2077. if(colorDialog.ShowDialog() == DialogResult.OK)
  2078. {
  2079. newColor = colorDialog.Color;
  2080. }
  2081. }
  2082. #endregion
  2083. #region 滤境
  2084. /// <summary>
  2085. /// 颜色。
  2086. /// </summary>
  2087. private void FadeInOut_Click(object sender, System.EventArgs e)
  2088. {
  2089. if(newImage==null)
  2090. return;
  2091. Point p = new Point(0,0);
  2092. int width;
  2093. int heigh;
  2094. width = newImage.Width;
  2095. heigh = newImage.Height;
  2096. Rectangle r= new Rectangle(p,new Size(width,heigh));
  2097. Image im = new Bitmap(width, heigh);
  2098. Graphics gr = Graphics.FromImage(im);
  2099. gr.FillRectangle(new SolidBrush(Color.White),r);
  2100. notchangeList.DrawList(gr);
  2101. newImage = im;
  2102. Graphics g=this.Drawing.CreateGraphics();
  2103. g.Clear(Color.Black);
  2104. Bitmap bitmap=(Bitmap)newImage;
  2105. int iWidth = bitmap.Width;
  2106. int iHeight = bitmap.Height;
  2107. //初始化色彩变换矩阵
  2108. float[][] tem={
  2109. new float[]{0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
  2110. new float[]{0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
  2111. new float[]{0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
  2112. new float[]{0.0f, 0.0f, 0.0f, 1.0f, 0.0f},
  2113. new float[]{0.0f, 0.0f, 0.0f, 0.0f, 1.0f}
  2114. };
  2115. ColorMatrix colorMatrix=new ColorMatrix(tem);
  2116. ImageAttributes imageAtt=new ImageAttributes();
  2117. //从0到1进行修改色彩变换矩阵主对角线上的数值
  2118. //使三种基准色的饱和度渐增
  2119. for(float i=0.0f;i<=1.0f;i+=0.02f)
  2120. {
  2121. colorMatrix.Matrix00=i;
  2122. colorMatrix.Matrix11=i;
  2123. colorMatrix.Matrix22=i;
  2124. colorMatrix.Matrix33=i;
  2125. //设置色彩校正矩阵
  2126. imageAtt.SetColorMatrix(colorMatrix,
  2127. ColorMatrixFlag.Default,ColorAdjustType.Bitmap);
  2128. //绘制图片
  2129. g.DrawImage(
  2130. bitmap, new Rectangle(0, 0, iWidth, iHeight),
  2131. 0,0,
  2132. iWidth,iHeight,
  2133. GraphicsUnit.Pixel,
  2134. imageAtt);
  2135. }
  2136. MessageBox.Show("下面演示淡出效果");
  2137. //从1到0进行修改色彩变换矩阵主对角线上的数值
  2138. //依次减少每种色彩分量
  2139. for(float i=1.0f;i>=0.0f;i-=0.02f)
  2140. {
  2141. colorMatrix.Matrix00=i;
  2142. colorMatrix.Matrix11=i;
  2143. colorMatrix.Matrix22=i;
  2144. colorMatrix.Matrix33=i;
  2145. //设置色彩校正矩阵
  2146. imageAtt.SetColorMatrix(colorMatrix,
  2147. ColorMatrixFlag.Default,ColorAdjustType.Bitmap);
  2148. //绘制图片
  2149. g.DrawImage(
  2150. bitmap, new Rectangle(0, 0, iWidth, iHeight),
  2151. 0,0,
  2152. iWidth,iHeight,
  2153. GraphicsUnit.Pixel,
  2154. imageAtt);
  2155. }
  2156. Drawing.Invalidate();
  2157. g.Dispose();
  2158. }
  2159. private void GrayScale1_Click(object sender, System.EventArgs e)
  2160. {
  2161. if(newImage==null)
  2162. return;
  2163. Graphics g=this.Drawing.CreateGraphics();
  2164. g.Clear(Color.White);
  2165. Bitmap image=(Bitmap)newImage;
  2166. int Width =image.Width-1;
  2167. int Height =image.Height-1;
  2168. Color color;
  2169. //使用平均值进行灰度处理
  2170. for(int i=Width; i>=0;i--)
  2171. for( int j=Height; j>=0;j--)
  2172. {
  2173. color=image.GetPixel(i,j);
  2174. //求出平均三个色彩分量的平均值
  2175. int middle=(color.R+
  2176. color.G+color.B)/3;
  2177. Color colorResult=Color.FromArgb(255,middle,middle,middle);
  2178. image.SetPixel(i, j, colorResult);
  2179. }
  2180. //重新绘制灰度化图
  2181. g.DrawImage(
  2182. image, new Rectangle(0, 0, Width, Height));
  2183. g.Dispose();
  2184. }
  2185. private void GrayScale2_Click(object sender, System.EventArgs e)
  2186. {
  2187. if(newImage==null)
  2188. return;
  2189. Graphics g=this.Drawing.CreateGraphics();
  2190. g.Clear(Color.White);
  2191. Bitmap image=(Bitmap)newImage;
  2192. int Width =image.Width-1;
  2193. int Height =image.Height-1;
  2194. Color color;
  2195. for(int i=Width; i>=0;i--)
  2196. {
  2197. for(int j=Height; j>=0;j--)
  2198. {
  2199. color=image.GetPixel(i,j);
  2200. int tmp=Math.Max(color.R,color.G);
  2201. int maxcolor=Math.Max(tmp,color.B);
  2202. Color colorResult=Color.FromArgb(255,maxcolor,maxcolor,maxcolor);
  2203. //设置处理后的灰度信息
  2204. image.SetPixel(i, j, colorResult);
  2205. }
  2206. }
  2207. //重新绘制灰度化图
  2208. g.DrawImage(
  2209. image, new Rectangle(0, 0, Width, Height));
  2210. g.Dispose();
  2211. }
  2212. private void grayScale3_Click(object sender, System.EventArgs e)
  2213. {
  2214. if(newImage==null)
  2215. return;
  2216. Graphics g=this.Drawing.CreateGraphics();
  2217. g.Clear(Color.White);
  2218. Bitmap image=(Bitmap)newImage;
  2219. int Width =image.Width-1;
  2220. int Height =image.Height-1;
  2221. Color color;
  2222. //使用加权平均法进行灰度处理
  2223. for(int i=Width; i>=0;i--)
  2224. {
  2225. for(int j=Height; j>=0;j--)
  2226. {
  2227. color=image.GetPixel(i, j);
  2228. int R=(int)(0.3f*color.R);
  2229. int G=(int)(0.59f*color.G);
  2230. int B=(int)(0.11f*color.B);
  2231. Color colorResult=Color.FromArgb(255,R,G,B);
  2232. //设置处理后的灰度信息
  2233. image.SetPixel(i, j, colorResult);
  2234. }
  2235. }
  2236. //重新绘制灰度化图
  2237. g.DrawImage(
  2238. image, new Rectangle(0, 0, Width, Height));
  2239. g.Dispose();
  2240. }
  2241. private void GrayScale4_Click(object sender, System.EventArgs e)
  2242. {
  2243. if(newImage==null)
  2244. return;
  2245. Graphics g=this.Drawing.CreateGraphics();
  2246. g.Clear(Color.White);
  2247. Bitmap image=(Bitmap)newImage;
  2248. int Width =image.Width-1;
  2249. int Height =image.Height-1;
  2250. Color color;
  2251. //灰度的还原演示,还原使用最大值法处理的灰度图像image2
  2252. for(int i=Width; i>0;i--)
  2253. {
  2254. for(int j=Height; j>0;j--)
  2255. {
  2256. color=image.GetPixel(i,j);
  2257. int R=color.R;
  2258. int G=color.G;
  2259. int B=color.B;
  2260. //分别对RGB三种色彩分量进行伪彩色还原
  2261. //进行红色分量的还原
  2262. if(R<127)
  2263. R=0;
  2264. if(R>=192)
  2265. R=255;
  2266. if(R<=191&&R>=128)
  2267. R=4*R-510;
  2268. /*进行绿色分量的还原,为了还原后的绿色分量再次参加比较,
  2269. 这里设置一个变量YES表示G是否已经参加了比较*/
  2270. bool yes;
  2271. yes=false;
  2272. if(G<=191&&G>=128&&(!yes))
  2273. {
  2274. G=255;
  2275. yes=true;
  2276. }
  2277. if(G>=192&&(!yes))
  2278. {
  2279. G=1022-4*G;
  2280. yes=true;
  2281. }
  2282. if(G<=63&&(!yes))
  2283. {
  2284. G=254-4*G;
  2285. yes=true;
  2286. }
  2287. if(G<=127&&G>=67&&(!yes))
  2288. G=4*G-257;
  2289. //进行蓝色分量的还原
  2290. if(B<=63)
  2291. B=255;
  2292. if(B>=128)
  2293. B=0;
  2294. if(B>=67&&B<=127)
  2295. B=510-4*B;
  2296. //还原后的伪彩色
  2297. Color colorResult=Color.FromArgb(255,R,G,B);
  2298. //将还原后的RGB信息重新写入位图
  2299. image.SetPixel(i, j, colorResult);
  2300. }
  2301. }
  2302. //重新绘制还原后的伪彩色位图
  2303. //重新绘制灰度化图
  2304. g.DrawImage(
  2305. image, new Rectangle(0, 0, Width, Height));
  2306. g.Dispose();
  2307. }
  2308. private void Inverse_Click(object sender, System.EventArgs e)
  2309. {
  2310. if(newImage==null)
  2311. return;
  2312. Graphics graphics=this.Drawing.CreateGraphics();
  2313. graphics.Clear(Color.White);
  2314. graphics.ScaleTransform(0.7f,0.7f);
  2315. Bitmap image=(Bitmap)newImage;
  2316. int Width =image.Width;
  2317. int Height =image.Height;
  2318. Color color;
  2319. //绘制原图
  2320. //graphics.DrawImage(
  2321. //image, new Rectangle(0, 0, Width, Height));
  2322. for(int i=0;i<Width;i++)
  2323. {
  2324. for( int j=0; j<Height;j++)
  2325. {
  2326. color=image.GetPixel(i, j);
  2327. //将色彩进行反转,获得底片效果
  2328. int r=255-color.R;
  2329. int g=255-color.G;
  2330. int b=255-color.B;
  2331. Color colorResult=Color.FromArgb(255,r,g,b);
  2332. //将还原后的RGB信息重新写入位图
  2333. image.SetPixel(i, j, colorResult);
  2334. }
  2335. //动态绘制底片滤镜效果图
  2336. graphics.DrawImage(
  2337. image, new Rectangle(0, 0, Width, Height));
  2338. }
  2339. //将已经实现了底片效果的位图再反色(恢复到原图)
  2340. for( int i=0;i<Width;i++)
  2341. {
  2342. for( int j=0; j<Height;j++)
  2343. {
  2344. color=image.GetPixel(i, j);
  2345. int r=255-color.R;
  2346. int g=255-color.G;
  2347. int b=255-color.B;
  2348. Color colorResult=Color.FromArgb(255,r,g,b);
  2349. //将还原后的RGB信息重新写入位图
  2350. image.SetPixel(i, j, colorResult);
  2351. }
  2352. //绘制经过两次反色的位图
  2353. graphics.DrawImage(
  2354. image, new Rectangle(0, 0, Width, Height));
  2355. }
  2356. graphics.Dispose();
  2357. }
  2358. private void Flashligt_Click(object sender, System.EventArgs e)
  2359. {
  2360. if(newImage==null)
  2361. return;
  2362. Graphics graphics=this.Drawing.CreateGraphics();
  2363. graphics.Clear(Color.White);
  2364. Bitmap image=(Bitmap)newImage;
  2365. int Width = image.Width;
  2366. int Height = image.Height;
  2367. int A=Width/2;
  2368. int B=Height/2;
  2369. //Center:图片中心点,发亮此值会让强光中心发生偏移
  2370. Point Center=new Point(A,B);
  2371. //R:强光照射面的半径,即”光晕”
  2372. int R=100;
  2373. Color color;
  2374. Color colorTemp;
  2375. //依次访问每个像素
  2376. for(int x=0;x<Width;x++)
  2377. {
  2378. for( int y=0; y<Height;y++)
  2379. {
  2380. Point tmp=new Point(x,y);
  2381. //如果像素位于”光晕”之内
  2382. if(fDistance(tmp,Center)<R)
  2383. {
  2384. color=image.GetPixel(x, y);
  2385. int r,g,b;
  2386. //根据该点距离强光中心点的距离,分别让RGB值变量
  2387. //220:亮度增加常量,该值越大,光亮度越强
  2388. float tmp_r=220.0f*(1.0f-fDistance(tmp,Center)/R);
  2389. r=color.R+(int)tmp_r;
  2390. r=Math.Max(0,Math.Min(r,255));
  2391. g=color.G+(int)tmp_r;
  2392. g=Math.Max(0,Math.Min(g,255));
  2393. b=color.B+(int)tmp_r;
  2394. b=Math.Max(0,Math.Min(b,255));
  2395. colorTemp=Color.FromArgb(255,(int)r,(int)g,(int)b);
  2396. //将增亮后的像素值回写到位图
  2397. image.SetPixel(x, y, colorTemp);
  2398. }
  2399. }
  2400. //动态绘制滤镜效果图
  2401. graphics.DrawImage(
  2402. image, new Rectangle(0, 0, Width, Height));
  2403. }
  2404. graphics.Dispose();
  2405. }
  2406. //计算两点A、B之间的绝对距离
  2407. float fDistance(Point A,Point B)
  2408. {
  2409. double i=Math.Pow((A.X-B.X),2)+Math.Pow((A.Y-B.Y),2);
  2410. return (float)Math.Sqrt(i);
  2411. }
  2412. private void BlurAndSharpen_Click(object sender, System.EventArgs e)
  2413. {
  2414. if(newImage==null)
  2415. return;
  2416. Graphics graphics=this.Drawing.CreateGraphics();
  2417. graphics.Clear(Color.White);
  2418. graphics.ScaleTransform(0.8f,0.8f);
  2419. //Image tempImage = (Image)newImage.Clone();
  2420. Bitmap image=(Bitmap)newImage;
  2421. int Width = image.Width;
  2422. int Height = image.Height;
  2423. //image2:进行锐化处理
  2424. //Bitmap image2=(Bitmap)newImage.Clone();
  2425. Color colorTemp;
  2426. Color[,] color=new Color[3,3];
  2427. for(int i=1;i<Width-2;i++)
  2428. {
  2429. for( int j=1; j<Height-2;j++)
  2430. {
  2431. //访问周围9个点的RGB值
  2432. color[0,0]=image.GetPixel(i-1, j-1);
  2433. color[0,1]=image.GetPixel(i-1, j);
  2434. color[0,2]=image.GetPixel(i-1, j+1);
  2435. color[1,0]=image.GetPixel(i, j-1);
  2436. color[1,1]=image.GetPixel(i, j);
  2437. color[1,2]=image.GetPixel(i, j+1);
  2438. color[2,0]=image.GetPixel(i+1, j-1);
  2439. color[2,1]=image.GetPixel(i+1, j);
  2440. color[2,2]=image.GetPixel(i+1, j+1);
  2441. int rSum=0;
  2442. int gSum=0;
  2443. int bSum=0;
  2444. //分别求出周围9个点的R、G、B之和
  2445. for(int n=0;n<3;n++)
  2446. for(int nn=0;nn<3;nn++)
  2447. {
  2448. rSum+=color[n,nn].R;
  2449. gSum+=color[n,nn].G;
  2450. bSum+=color[n,nn].B;
  2451. }
  2452. //用RGB的平均值做为当前点的RGB值
  2453. colorTemp=Color.FromArgb(255,
  2454. (int)(rSum/9),(int)(gSum/9),(int)(bSum/9));
  2455. //将计算后的RGB值回写到位图
  2456. image.SetPixel(i, j,colorTemp);
  2457. }
  2458. //绘制经过平滑处理的效果图
  2459. graphics.DrawImage(
  2460. image, new Rectangle(0, 0, Width, Height));
  2461. }
  2462. //进行锐化处理
  2463. Bitmap image2=(Bitmap)newImage.Clone();
  2464. Color colorLeft,colornow;
  2465. //常量dep:锐化系数,此值越大,锐化效果越明显
  2466. float dep=0.550f;
  2467. for(int i=1;i<Width-1; i++)
  2468. {
  2469. for( int j=1;j<Height-1; j++)
  2470. {
  2471. colornow=image2.GetPixel(i, j);
  2472. colorLeft=image2.GetPixel(i-1, j-1);
  2473. float r=colornow.R+(colornow.R
  2474. -colorLeft.R*dep);
  2475. r=Math.Min(255,Math.Max(0,r));
  2476. float g=colornow.G+(colornow.G
  2477. -colorLeft.G*dep);
  2478. g=Math.Min(255,Math.Max(0,g));
  2479. float b=colornow.B+(colornow.B
  2480. -colorLeft.B*dep);
  2481. b=Math.Min(255,Math.Max(0,b));
  2482. colorTemp=Color.FromArgb(255,(int)r,(int)g,(int)b);
  2483. //将计算后的RGB值回写到位图
  2484. image.SetPixel(i, j, colorTemp);
  2485. }
  2486. graphics.DrawImage(
  2487. image2, new Rectangle(0, 0, Width, Height));
  2488. }
  2489. graphics.Dispose();
  2490. }
  2491. #endregion
  2492. }
  2493. }