首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

C#图像处理有关问题

2013-08-04 
C#图像处理问题using Systemusing System.Collections.Genericusing System.ComponentModelusing Syste

C#图像处理问题
C#图像处理有关问题

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication14
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void 打开图像_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "BMP FILE|*.jpg";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                Bitmap curMap = new Bitmap(openFileDialog1.FileName);
                pictureBox1.Image = curMap;
                
            }
        }

        private void 提取图像_Click(object sender, EventArgs e)
        {
            if (pictureBox1.Image != null)
            {

                this.label1.Text = "";
                int width1, width2, height1, height2;
                int r1, r2;
                int g1, g2;
                int b1, b2;
                Color c1 =new Color() ;


                Color c2 = new Color();
                //定义两个Bitmap,分别接受连个pictureBox1中的图像
                Bitmap box1 = new Bitmap(pictureBox1.Image);
                int j = 0;
                int mark = 0;
                int k = 1;
                //算法核心,先竖向扫描,如果出现多个点的R的颜色雷同,
                //就能判断该坐标的竖线就是一条矩形边所在的直线,得到一个width1的坐标值;
                for ( width1 = 0; width1 < pictureBox1.Image.Width; width1++)
                {
                    for(j =0 ;j<pictureBox1.Height-219 ;j++)
                    {
                        c1 = box1.GetPixel(width1, j);
                        r1 = c1.R;
                        g1 = c1.G;
                        b1 = c1.B;
                        for (k = 1; k < 219; k++)
                        {
                            c2 = box1.GetPixel(width1, k);
                            r2 = c2.R;


                            g2 = c2.G;
                            b2 = c2.B;
                            if (c1 != c2)
                            {
                                break;
                            }

                        }
                        if(k==219)
                        {
                            mark = 1;
                            break;
                        }
                    }
                    if (mark == 1)
                    {
                        break;
                    }

                }
                height1 = j;


                height2 = j + 219;
                width2 = width1 + 185;
                Bitmap box2 = new Bitmap(186, 220);
                int x = 1;
                int y = 1;
                for (int i = width1; i < width2; i++)
                {

                    for (int w = height1; w < height2; w++)
                    {
                        c2 = box1.GetPixel(i, w);

                        box2.SetPixel(x, y, c2);
                        y++;
                    }
                    x++;
                    y = 0;
                }
                pictureBox2.Image = box2;
                

            }
        }
    }
}


[解决办法]
这错报的还不够明显么?
[解决办法]
智商拙计。。

热点排行