www.pudn.com > picCompare.rar > Form1.cs, change:2008-06-15,size:2417b


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; 
//using CSharpChat; 
using System.Runtime.InteropServices; 
 
namespace 图片处理 
{ 
    public partial class Form1 : Form 
    { 
        public Bitmap combine; 
        public int nStartX; 
        public Form1() 
        { 
            InitializeComponent(); 
            combine = new Bitmap(473, 353); 
            for (int x = 0; x < 473; ++x) 
            { 
                for (int y = 0; y < 353; ++y) 
                { 
                    Color crCombin = new Color(); 
                    crCombin = Color.FromArgb(255, 0, 0, 0); 
                    combine.SetPixel(x, y, crCombin); 
                } 
            } 
        } 
 
        private void button1_Click(object sender, EventArgs e) 
        { 
            Bitmap bmpLeft = (Bitmap)pictureBox1.Image; 
            Bitmap bmpRight = (Bitmap)pictureBox2.Image; 
            int r,g,b; 
            for (int x = 0; x < 473; x++) 
            { 
                for (int y = 0; y < 353; y++) 
                { 
                    Color crLeft, crRight; 
                    Color crCombin = new Color(); 
                    crLeft = bmpLeft.GetPixel(x, y); 
                    crRight = bmpRight.GetPixel(x, y); 
 
                    // 仅仅处理图像中的红色 
                    r = System.Math.Abs(crLeft.R - crRight.R); 
                    r = (r > 10) ? 255 : 0; 
                    g = System.Math.Abs(crLeft.G - crRight.G); 
                    g = (g > 10) ? 255 : 0; 
                    b = System.Math.Abs(crLeft.B - crRight.B); 
                    b = (b > 10) ? 255 : 0; 
 
                    crCombin = Color.FromArgb(255, g, g, g); 
                    if (g == 255) 
                    { 
                        for (int i = x - 5; i <= x+5; i++) 
                        { 
                            for (int j = y - 5; j <= y+5; j++) 
                            { 
                                combine.SetPixel(i, j, crCombin); 
                            } 
 
                        } 
                    } 
                     
                     
                } 
            } 
            this.pictureBox3.Image = combine; 
            this.pictureBox3.Update(); 
 
 
        } 
    } 
}