SHOW:
|
|
- or go back to the newest paste.
1 | /* | |
2 | * Created by SharpDevelop. | |
3 | * User: fhrl0 | |
4 | * Date: 14/09/2019 | |
5 | * Time: 02:04 p. m. | |
6 | - | * Vertion: 0.3.0 |
6 | + | * Vertion: 0.3.1 |
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers. | |
8 | */ | |
9 | using System; | |
10 | using System.Collections.Generic; | |
11 | using System.Drawing; | |
12 | using System.Windows.Forms; | |
13 | - | |
13 | + | |
14 | namespace Actividad_2{ | |
15 | - | /// <summary> |
15 | + | /// <summary> |
16 | - | /// Description of MainForm. |
16 | + | /// Description of MainForm. |
17 | - | /// </summary> |
17 | + | /// </summary> |
18 | - | public partial class MainForm : Form{ |
18 | + | public partial class MainForm : Form{ |
19 | - | Bitmap Original,Drawing; |
19 | + | Bitmap Original,Drawing; |
20 | - | public MainForm(){ |
20 | + | public MainForm(){ |
21 | - | // |
21 | + | // |
22 | - | // The InitializeComponent() call is required for Windows Forms designer support. |
22 | + | // The InitializeComponent() call is required for Windows Forms designer support. |
23 | - | // |
23 | + | // |
24 | - | InitializeComponent(); |
24 | + | InitializeComponent(); |
25 | - | |
25 | + | |
26 | - | // |
26 | + | // |
27 | - | // TODO: Add constructor code after the InitializeComponent() call. |
27 | + | // TODO: Add constructor code after the InitializeComponent() call. |
28 | - | // |
28 | + | // |
29 | - | } |
29 | + | } |
30 | - | int codificador(bool[]arregloBits){//fixed |
30 | + | int codificador(bool[]arregloBits){//fixed |
31 | - | int abstracto=0; |
31 | + | int abstracto=0; |
32 | - | for(int i=0;i<arregloBits.Length;i++){ |
32 | + | for(int i=0;i<arregloBits.Length;i++){ |
33 | - | abstracto=abstracto*2; |
33 | + | abstracto=abstracto*2; |
34 | - | if(arregloBits[i]) |
34 | + | if(arregloBits[i]) |
35 | - | abstracto++; |
35 | + | abstracto++; |
36 | - | }//else es inesesario incrmentar. |
36 | + | }//else es inesesario incrmentar. |
37 | - | return abstracto; |
37 | + | return abstracto; |
38 | - | } |
38 | + | } |
39 | - | bool esNegro(int x,int y){ |
39 | + | bool esNegro(int x,int y){ |
40 | - | return(int)Original.GetPixel(x,y).R |
40 | + | return(int)Original.GetPixel(x,y).R |
41 | - | +(int)Original.GetPixel(x,y).G |
41 | + | +(int)Original.GetPixel(x,y).G |
42 | - | +(int)Original.GetPixel(x,y).B<(int)383; |
42 | + | +(int)Original.GetPixel(x,y).B<(int)383; |
43 | - | } |
43 | + | } |
44 | - | void centra(int xInicio,int yInicio,int xFin,int yFin){//163 >> 1 |
44 | + | void centra(int xInicio,int yInicio,int xFin,int yFin){//163 >> 1 |
45 | - | buttonMostrar.Text=yFin.ToString(); |
45 | + | buttonMostrar.Text=yFin.ToString(); |
46 | - | Drawing.SetPixel(xInicio,yInicio,Color.Yellow); |
46 | + | Drawing.SetPixel(xInicio,yInicio,Color.Yellow); |
47 | - | for(bool[]sentencias={esNegro(xInicio,yInicio),esNegro(xFin,yFin)};true;){ |
47 | + | for(bool[]sentencias={esNegro(xInicio,yInicio),esNegro(xFin,yFin)};true;){ |
48 | - | switch(codificador(sentencias)){ |
48 | + | switch(codificador(sentencias)){ |
49 | - | case 0:{//00? |
49 | + | case 0:{//00? |
50 | - | }return; |
50 | + | }return; |
51 | - | case 1:{//10? |
51 | + | case 1:{//10? |
52 | - | //yFin=yFin+i; |
52 | + | //yFin=yFin+i; |
53 | - | }return; |
53 | + | }return; |
54 | - | case 2:{//01? |
54 | + | case 2:{//01? |
55 | - | //yFin=yFin-i; |
55 | + | //yFin=yFin-i; |
56 | - | }return; |
56 | + | }return; |
57 | - | case 3:{//11? |
57 | + | case 3:{//11? |
58 | - | //yFin=yFin-i; |
58 | + | //yFin=yFin-i; |
59 | - | }return; |
59 | + | }return; |
60 | - | default:return; |
60 | + | default:return; |
61 | - | }; |
61 | + | }; |
62 | - | } |
62 | + | } |
63 | - | } |
63 | + | } |
64 | - | void detecta(int xInicio,int yInicio,int xFin,int yFin){//Drawing.SetPixel(xInicio,yInicio,Color.BlueViolet);//para analisis.//int xCentro=(xInicio+xFin)/2,yCentro=(yInicio+yFin)/2; |
64 | + | void detecta(int xInicio,int yInicio,int xFin,int yFin){//Drawing.SetPixel(xInicio,yInicio,Color.BlueViolet);//para analisis.//int xCentro=(xInicio+xFin)/2,yCentro=(yInicio+yFin)/2; |
65 | - | int xCentro=(xInicio+xFin)/2, |
65 | + | int xCentro=(xInicio+xFin)/2, |
66 | - | yCentro=(yInicio+yFin)/2; |
66 | + | yCentro=(yInicio+yFin)/2; |
67 | - | for(bool[]tipoVorde={esNegro(xInicio,yInicio),esNegro(xFin,yInicio), |
67 | + | for(bool[]tipoVorde={esNegro(xInicio,yInicio),esNegro(xFin,yInicio), |
68 | - | esNegro(xInicio,yFin),esNegro(xFin,yFin)}; |
68 | + | esNegro(xInicio,yFin),esNegro(xFin,yFin)}; |
69 | - | esNegro(xCentro,yCentro);) |
69 | + | esNegro(xCentro,yCentro)&&(!Equals(Drawing.GetPixel(xCentro,yCentro),Color.OrangeRed)); |
70 | - | switch(codificador(tipoVorde)){ |
70 | + | xCentro=(xInicio+xFin)/2,yCentro=(yInicio+yFin)/2) |
71 | - | case 0:case 15:return;// x <-nombrar_como. |
71 | + | switch(codificador(tipoVorde)){ |
72 | - | case 10:{// < |
72 | + | case 0:case 15:return;// x <-nombrar_como. |
73 | - | xCentro=(xInicio+xFin)/2; |
73 | + | case 12:{// < 10 //patch |
74 | - | yCentro=(yInicio+yFin)/2; |
74 | + | Drawing.SetPixel(xInicio,yInicio,Color.Blue); |
75 | - | Drawing.SetPixel(xCentro,yCentro,Color.OrangeRed); |
75 | + | Drawing.SetPixel(xInicio,yFin,Color.Blue); |
76 | - | if(esNegro(xCentro,yInicio-1)){yInicio--; |
76 | + | Drawing.SetPixel(xFin,yInicio,Color.Blue); |
77 | - | if(esNegro(xCentro,yFin+1)){yFin++; |
77 | + | Drawing.SetPixel(xFin,yFin,Color.Blue);//*/ |
78 | - | if(esNegro(xInicio-1,yCentro)){xInicio--; |
78 | + | Drawing.SetPixel(xCentro,yCentro,Color.OrangeRed);//pictureBoxMuestra.Refresh(); |
79 | - | if(esNegro(xFin+1,yCentro)){xFin++;}else{} |
79 | + | if(yInicio>=0&&esNegro(xCentro,yInicio-1)){yInicio--; |
80 | - | }else{ |
80 | + | if(yFin<Original.Height-1&&esNegro(xCentro,yFin+1)){yFin++; |
81 | - | if(esNegro(xFin+1,yCentro)){xFin++;}else{} |
81 | + | if(xInicio>=0&&esNegro(xInicio-1,yCentro)){xInicio--; |
82 | - | } |
82 | + | if(xFin<Original.Width-1&&esNegro(xFin+1,yCentro)){xFin++;}else{} |
83 | - | }else{ |
83 | + | }else{ |
84 | - | if(esNegro(xInicio-1,yCentro)){xInicio--; |
84 | + | if(xFin<Original.Width-1&&esNegro(xFin+1,yCentro)){xFin++;}else{} |
85 | - | if(esNegro(xFin+1,yCentro)){xFin++;}else{} |
85 | + | } |
86 | - | }else{ |
86 | + | }else{ |
87 | - | if(esNegro(xFin+1,yCentro)){xFin++;}else{} |
87 | + | if(xInicio>=0&&esNegro(xInicio-1,yCentro)){xInicio--; |
88 | - | } |
88 | + | if(xFin<Original.Width-1&&esNegro(xFin+1,yCentro)){xFin++;}else{} |
89 | - | |
89 | + | }else{ |
90 | - | } |
90 | + | if(xFin<Original.Width-1&&esNegro(xFin+1,yCentro)){xFin++;}else{} |
91 | - | }else{ |
91 | + | } |
92 | - | if(esNegro(xCentro,yFin+1)){yFin++; |
92 | + | |
93 | - | if(esNegro(xInicio-1,yCentro)){xInicio--; |
93 | + | } |
94 | - | if(esNegro(xFin+1,yCentro)){xFin++;}else{} |
94 | + | }else{ |
95 | - | }else{ |
95 | + | if(yFin<Original.Height-1&esNegro(xCentro,yFin+1)){yFin++; |
96 | - | if(esNegro(xFin+1,yCentro)){xFin++;}else{} |
96 | + | if(xInicio>=0&&esNegro(xInicio-1,yCentro)){xInicio--; |
97 | - | } |
97 | + | if(xFin<Original.Width-1&&esNegro(xFin+1,yCentro)){xFin++;}else{} |
98 | - | }else{ |
98 | + | }else{ |
99 | - | if(esNegro(xInicio-1,yCentro)){xInicio--; |
99 | + | if(xFin<Original.Width-1&&esNegro(xFin+1,yCentro)){xFin++;}else{} |
100 | - | if(esNegro(xFin+1,yCentro)){xFin++;}else{} |
100 | + | } |
101 | - | }else{ |
101 | + | }else{ |
102 | - | if(esNegro(xFin+1,yCentro)){xFin++;}else{Drawing.SetPixel(xCentro,yCentro,Color.OrangeRed);return;} |
102 | + | if(xInicio>=0&&esNegro(xInicio-1,yCentro)){xInicio--; |
103 | - | } |
103 | + | if(xFin<Original.Width-1&&esNegro(xFin+1,yCentro)){xFin++;}else{} |
104 | - | |
104 | + | }else{ |
105 | - | } |
105 | + | if(xFin<Original.Width-1&&esNegro(xFin+1,yCentro)){xFin++;}else{Drawing.SetPixel(xCentro,yCentro,Color.OrangeRed);pictureBoxMuestra.Refresh();buttonMostrar.Text=xCentro.ToString()+",".ToString()+yCentro.ToString();buttonMostrar.Refresh();return;} |
106 | - | } |
106 | + | } |
107 | - | }break;//return; |
107 | + | |
108 | - | /*case 2:case 11:{/// L |
108 | + | } |
109 | - | Drawing.SetPixel(x,y,Color.Red); |
109 | + | } |
110 | - | for(;esNegro(x-n,y+n) |
110 | + | }break;//return; |
111 | - | &&(x-n>=0) |
111 | + | /*case 2:case 11:{/// L |
112 | - | &&(y+n<Original.Width);n++) |
112 | + | Drawing.SetPixel(x,y,Color.Red); |
113 | - | Drawing.SetPixel(x-n,y+n,Color.Blue); |
113 | + | for(;esNegro(x-n,y+n) |
114 | - | return; |
114 | + | &&(x-n>=0) |
115 | - | } |
115 | + | &&(y+n<Original.Width);n++) |
116 | - | case 3:{/// v |
116 | + | Drawing.SetPixel(x-n,y+n,Color.Blue); |
117 | - | Drawing.SetPixel(x,y,Color.Red); |
117 | + | return; |
118 | - | for(;esNegro(x,y+n) |
118 | + | } |
119 | - | &&(y+n<Original.Width);n++) |
119 | + | case 3:{/// v |
120 | - | Drawing.SetPixel(x,y+n,Color.Blue); |
120 | + | Drawing.SetPixel(x,y,Color.Red); |
121 | - | return; |
121 | + | for(;esNegro(x,y+n) |
122 | - | } |
122 | + | &&(y+n<Original.Width);n++) |
123 | - | case 1:case 7:{// _| |
123 | + | Drawing.SetPixel(x,y+n,Color.Blue); |
124 | - | Drawing.SetPixel(x,y,Color.Red); |
124 | + | return; |
125 | - | /*for(;esNegro(x+n,y+n) |
125 | + | } |
126 | - | &&(y+n<Original.Width) |
126 | + | case 1:case 7:{// _| |
127 | - | &&(x+n<Original.Height);n++) |
127 | + | Drawing.SetPixel(x,y,Color.Red); |
128 | - | Drawing.SetPixel(x+n,y+n,Color.Blue); |
128 | + | /*for(;esNegro(x+n,y+n) |
129 | - | return; |
129 | + | &&(y+n<Original.Width) |
130 | - | } |
130 | + | &&(x+n<Original.Height);n++) |
131 | - | case 5:{// > |
131 | + | Drawing.SetPixel(x+n,y+n,Color.Blue); |
132 | - | Drawing.SetPixel(x,y,Color.Red); |
132 | + | return; |
133 | - | /*for(;(esNegro(x+n,y)) |
133 | + | } |
134 | - | &&(x+n<Original.Height);n++) |
134 | + | case 5:{// > |
135 | - | Drawing.SetPixel(x+n,y,Color.Blue); |
135 | + | Drawing.SetPixel(x,y,Color.Red); |
136 | - | return; |
136 | + | /*for(;(esNegro(x+n,y)) |
137 | - | } |
137 | + | &&(x+n<Original.Height);n++) |
138 | - | case 4:case 13:{// ¬ |
138 | + | Drawing.SetPixel(x+n,y,Color.Blue); |
139 | - | Drawing.SetPixel(x,y,Color.Red); |
139 | + | return; |
140 | - | for(;esNegro(x+n,y-n) |
140 | + | } |
141 | - | &&((x+n<Original.Height) |
141 | + | case 4:case 13:{// ¬ |
142 | - | &&(y-n>=0));n++) |
142 | + | Drawing.SetPixel(x,y,Color.Red); |
143 | - | Drawing.SetPixel(x+n,y-n,Color.Blue); |
143 | + | for(;esNegro(x+n,y-n) |
144 | - | return; |
144 | + | &&((x+n<Original.Height) |
145 | - | } |
145 | + | &&(y-n>=0));n++) |
146 | - | case 12:{// ^ |
146 | + | Drawing.SetPixel(x+n,y-n,Color.Blue); |
147 | - | Drawing.SetPixel(x,y,Color.Red); |
147 | + | return; |
148 | - | for(;esNegro(x,y-n) |
148 | + | } |
149 | - | &&(y-n>=0);n++) |
149 | + | case 12:{// ^ |
150 | - | Drawing.SetPixel(x,y-n,Color.Blue); |
150 | + | Drawing.SetPixel(x,y,Color.Red); |
151 | - | return; |
151 | + | for(;esNegro(x,y-n) |
152 | - | } |
152 | + | &&(y-n>=0);n++) |
153 | - | case 8:case 14:{// F |
153 | + | Drawing.SetPixel(x,y-n,Color.Blue); |
154 | - | Drawing.SetPixel(x,y,Color.Red); |
154 | + | return; |
155 | - | for(n=0;n>9;n++) |
155 | + | } |
156 | - | Drawing.SetPixel(x-n,y-n,Color.Red); |
156 | + | case 8:case 14:{// F |
157 | - | for(;esNegro(x-n,y-n) |
157 | + | Drawing.SetPixel(x,y,Color.Red); |
158 | - | &&((x-n>=0) |
158 | + | for(n=0;n>9;n++) |
159 | - | &&(y-n>=0));n++) |
159 | + | Drawing.SetPixel(x-n,y-n,Color.Red); |
160 | - | Drawing.SetPixel(x-n,y-n,Color.Blue); |
160 | + | for(;esNegro(x-n,y-n) |
161 | - | return; |
161 | + | &&((x-n>=0) |
162 | - | }*/ |
162 | + | &&(y-n>=0));n++) |
163 | - | default:return; |
163 | + | Drawing.SetPixel(x-n,y-n,Color.Blue); |
164 | - | //Drawing.SetPixel(x,y,Color.Red); |
164 | + | return; |
165 | - | //break;ruido |
165 | + | }*/ |
166 | - | } |
166 | + | default:return; |
167 | - | } |
167 | + | //Drawing.SetPixel(x,y,Color.Red); |
168 | - | void analizar(int xInicio,int yInicio,int xFin,int yFin){//dispose objetos//principio de animacion |
168 | + | //break;ruido |
169 | - | int xCentro=(xInicio+xFin)/2, |
169 | + | } |
170 | - | yCentro=(yInicio+yFin)/2; |
170 | + | } |
171 | - | detecta(xInicio,yInicio,xFin,yFin); |
171 | + | void analizar(int xInicio,int yInicio,int xFin,int yFin){//dispose objetos//principio de animacion |
172 | - | //System.Threading.Thread.Sleep(10); |
172 | + | int xCentro=(xInicio+xFin)/2, |
173 | - | bool[]sentencias={xInicio+2<xFin-2,yInicio+2<yFin-2}; |
173 | + | yCentro=(yInicio+yFin)/2; |
174 | - | switch(codificador(sentencias)){//enum{}? |
174 | + | detecta(xInicio,yInicio,xFin,yFin); |
175 | - | case 1://01 |
175 | + | //System.Threading.Thread.Sleep(10); |
176 | - | analizar(xInicio,yInicio,xFin,yCentro-1); |
176 | + | bool[]sentencias={xInicio+1<xFin-1,yInicio+1<yFin-1}; |
177 | - | analizar(xInicio,yCentro,xFin,yFin); |
177 | + | switch(codificador(sentencias)){//enum{}? |
178 | - | return; |
178 | + | case 1://01 |
179 | - | case 2://10 |
179 | + | analizar(xInicio,yInicio,xFin,yCentro-1); |
180 | - | analizar(xInicio,yInicio,xCentro-1,yFin);analizar(xCentro,yInicio,xFin,yFin); |
180 | + | analizar(xInicio,yCentro,xFin,yFin); |
181 | - | return; |
181 | + | return; |
182 | - | case 3://11 |
182 | + | case 2://10 |
183 | - | //a por definir descarte |
183 | + | analizar(xInicio,yInicio,xCentro-1,yFin);analizar(xCentro,yInicio,xFin,yFin); |
184 | - | analizar(xInicio,yInicio,xCentro-1,yCentro-1);analizar(xCentro,yInicio,xFin,yCentro-1); |
184 | + | return; |
185 | - | analizar(xInicio,yCentro,xCentro-1,yFin); analizar(xCentro,yCentro,xFin,yFin); |
185 | + | case 3://11 |
186 | - | return; |
186 | + | //a por definir descarte |
187 | - | default:return;//00 |
187 | + | analizar(xInicio,yInicio,xCentro-1,yCentro-1);analizar(xCentro,yInicio,xFin,yCentro-1); |
188 | - | } |
188 | + | analizar(xInicio,yCentro,xCentro-1,yFin); analizar(xCentro,yCentro,xFin,yFin); |
189 | - | } |
189 | + | return; |
190 | - | void ButtonMostrarClick(object sender, EventArgs e){ |
190 | + | default:return;//00 |
191 | - | if(pictureBoxMuestra.Image==null){ |
191 | + | } |
192 | - | }else{ |
192 | + | } |
193 | - | Original=(Bitmap)pictureBoxMuestra.Image; |
193 | + | void ButtonMostrarClick(object sender, EventArgs e){ |
194 | - | Drawing=(Bitmap)Original; |
194 | + | if(pictureBoxMuestra.Image==null){ |
195 | - | analizar(0,0,Original.Width-1,Original.Height-1); |
195 | + | }else{ |
196 | - | pictureBoxMuestra.Refresh(); |
196 | + | Original=(Bitmap)pictureBoxMuestra.Image; |
197 | - | //pictureBoxMuestra.Image=Drawing; |
197 | + | Drawing=(Bitmap)Original; |
198 | - | } |
198 | + | analizar(0,0,Original.Width-1,Original.Height-1); |
199 | - | } |
199 | + | pictureBoxMuestra.Refresh(); |
200 | - | void ButtonAbrirMouseClick(object sender, MouseEventArgs e){ |
200 | + | //pictureBoxMuestra.Image=Drawing; |
201 | - | openFileDialogImagen.ShowDialog(); |
201 | + | } |
202 | - | pictureBoxMuestra.Image=Image.FromFile(openFileDialogImagen.FileName); |
202 | + | } |
203 | - | } |
203 | + | void ButtonAbrirMouseClick(object sender, MouseEventArgs e){ |
204 | - | } |
204 | + | openFileDialogImagen.ShowDialog(); |
205 | pictureBoxMuestra.Image=Image.FromFile(openFileDialogImagen.FileName); | |
206 | } | |
207 | } | |
208 | } |