
前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
Face App;
int val= 20; // 閾値
public MyForm()
{
App = new Face();
App.edge = (Bitmap)App.bmp.Clone();
Width = App.bmp.Width+16;
Height = App.bmp.Height+42;
Paint += new PaintEventHandler(MyHandler);
MouseDown += new MouseEventHandler(OnMyMouseDown);
}
|
if (e.Button == MouseButtons.Left) //マウスの左ボタン
{ val += 10;
App.Edge(33000);
App.HLine(val);
App.VLine(val);
VerMsg("val: ", val);
}
if (e.Button == MouseButtons.Right) //マウスの右ボタン
{ App.edge = (Bitmap)App.bmp.Clone();
val= 20;
}
Invalidate();
|
// 横線を調べて edge 画像に Red を設定する
public void HLine(int val)
{ Color cor;
int x,y,wk;
for(y=1; y<bmp.Height-1; y++)
for(x=1; x<bmp.Width-1; x++)
{ cor = edge.GetPixel(x,y);
if (cor.R==0)
{ for(wk=x; wk<edge.Width-1; wk++)
{ cor = edge.GetPixel(wk,y);
if (cor.R!=0) break;
}
if ((wk-x)>val)
{ cor = Color.Red;
for(wk--; wk>=x; wk--) edge.SetPixel(wk,y,cor);
}
}
}
}
|
// 縦線を調べて edge 画像に Green を設定する
public void VLine(int val)
{ Color cor;
int x,y,wk;
for(x=1; x<bmp.Width-1; x++)
for(y=1; y<bmp.Height-1; y++)
{ cor = edge.GetPixel(x,y);
if (cor.G==0)
{ for(wk=y; wk<edge.Height-1; wk++)
{ cor = edge.GetPixel(x,wk);
if (cor.G!=0) break;
}
if ((wk-y)>val)
{ cor = Color.Green;
for(wk--; wk>=y; wk--) edge.SetPixel(x,wk,cor);
}
}
}
}
|
![]()
if (e.Button == MouseButtons.Left) //マウスの左ボタン
{ val += 10;
App.Edge(33000);
App.Line(1,0,val);
App.Line(0,1,val);
App.Line(1,1,val);
App.Line(1,-1,val);
VerMsg("val: ", val);
}
|
// Line を検出して edge 画像に Red を設定する
public void Line(int dx, int dy, int val)
{ Color cor;
int x,y,wx,wy,cnt;
for(x=1; x<bmp.Width-1; x++)
for(y=1; y<bmp.Height-1; y++)
{ cor = edge.GetPixel(x,y);
if (cor.R==0)
{ wx = x;
wy = y;
for(cnt=0; ; cnt++,wx+=dx,wy+=dy)
{ if (wx<0 || wx>=bmp.Width || wy<0 || wy>=bmp.Height) break;
cor = edge.GetPixel(wx,wy);
if (cor.R!=0) break;
}
if (cnt>val)
{ cor = Color.Red;
wx = x;
wy = y;
for(; cnt>=0; cnt--,wx+=dx,wy+=dy)
{ edge.SetPixel(wx, wy, cor); }
}
}
}
}
|
![]()
if (e.Button == MouseButtons.Left) //マウスの左ボタン
{ val += 10;
App.Edge(33000);
App.Line(1, (float)0.6, val);
App.Line(1,(float)-0.6,val);
App.Line(1,(float)1.2,val);
App.Line(1,(float)-1.2,val);
VerMsg("val: ", val);
}
|
// float で Line を調べて edge 画像に Red を設定する
public void Line(float dx, float dy, int val)
{ Color cor;
int x,y,cnt,ix,iy;
float wx,wy;
for(x=1; x<bmp.Width-1; x++)
for(y=1; y<bmp.Height-1; y++)
{ cor = edge.GetPixel(x,y);
if (cor.R==0)
{ wx = x;
wy = y;
for(cnt=0; (int)wy>0; cnt++,wx+=dx,wy+=dy)
{ ix = (int)wx;
iy = (int)wy;
if (ix < 0 || ix >= bmp.Width || iy < 0 || iy >= bmp.Height) break;
cor = edge.GetPixel((int)wx,(int)wy);
if (cor.R!=0) break;
}
if (cnt>val)
{ cor = Color.Red;
wx = x;
wy = y;
for(; cnt>=0; cnt--,wx+=dx,wy+=dy)
{ edge.SetPixel((int)wx,(int)wy,cor); }
}
}
}
}
|
![]()
[Next Chapter ↓] BitBlt
[Previous Chapter ↑] Color ⇒ エッジ画像