Mungkin bermanfaat untuk Anda tetapi sudah terlambat ketika saya mengunjungi situs ini hari ini
Bitmap bmp=new Bitmap(pictureBox1.Image);
int x1=0, x2=0, y1=0, y2=0;
for (int i = 1; i < bmp.Height;i++ )
{
for (int j = 1; j < bmp.Width;j++ )
{
if( bmp.GetPixel(j,i).R<7 && bmp.GetPixel(j-1,i).R>240 && bmp.GetPixel(j,i-1).R>240 ){
for (int k = j; k < bmp.Width - 1;k++ )
{
if ((bmp.GetPixel(k, i).R < 7) && (bmp.GetPixel(k+1, i).R > 240) && (k-j>30)) {
int count1 = 0;
for (int g = j; g < k;g++ ){
if(bmp.GetPixel(g,i).R<7){
count1++;
}
}//get total width
if(count1==k-j){
x1 = j;
y1 = i;
x2 = k;
}
}
}
for (int a = i; a < bmp.Height - 1;a++ )
{
if ((bmp.GetPixel(j, a).R < 7) && (bmp.GetPixel(j, a+1).R > 240) && (a- i > 30)) {
int count2 = 0;
for (int x = i; x < a;x++ )
{
if(bmp.GetPixel(j,x).R<7){
count2++;
}
}
if (count2 == (a - i))
{
y2 = a;
}
else {
Console.WriteLine("check");
}
}
}
if ((bmp.GetPixel(x2, y2).R < 7) && (bmp.GetPixel(x2 + 1, y2).R > 240) && (bmp.GetPixel(x2, y2+1).R > 240))
{
bool r1 = false;
bool r2 = false;
int count3 = 0;
for (int y = y1; y < y2;y++ )
{
if(bmp.GetPixel(x2,y).R<7){
count3++;
}
}
if (count3== y2 - y1) {
r1 = true;
}
if(r1==true){
int count4=0;
for (int x = x1; x < x2;x++ )
{
if(bmp.GetPixel(x,y1).R<7){
count4++;
}
}
if(count4==x2-x1){
r2 = true;
Console.WriteLine("values : X1 " + x1 + " y1 :" + y1 + " width : " + (x2 - x1) + " height : " + (y2 - y1));
Pen pen = new Pen(Color.Red, 2);
pictureBox1.CreateGraphics().DrawRectangle(pen, x1, y1, x2 - x1, y2 - y1);
}
}
}
}
}// initial point loop
}// first if