using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace 图片处理
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void button1_Click(object sender, EventArgs e)
        {
            Color c1, c2;
            int r, g, b;
            Bitmap im = new Bitmap(pictureBox1.Image);
            Bitmap im1 = new Bitmap(im);
            for (int i = 0; i < im.Width - 1; i++)
                for (int j = 0; j < im.Height - 1; j++)
                {
                    c1 = im.GetPixel(i, j);
                    c2 = im.GetPixel(i + 1, j + 1);
                    r = Math.Abs(c1.R - c2.R) + 128;
                    g = Math.Abs(c1.G - c2.G) + 128;
                    b = Math.Abs(c1.B - c2.B) + 128;
                    if (r < 0) r = 0;
                    if (r > 255) r = 255;
                    if (g < 0) g = 0;
                    if (g > 255) g = 255;
                    if (b < 0) b = 0;
                    if (b > 255) b = 255;
                    Color cc = Color.FromArgb(r, g, b);
                    im1.SetPixel(i, j, cc);
                }
            pictureBox2.Image = im1;
        }
    }
}

解决方案 »

  1.   

    未处理   NullReferenceException未将对象引用设置到对象的实例。
    排错提示:
    使用“new”关键字创建对象实例。
    在调用方法前通过检查确定对象是否为空。
    获取此异常的常规帮助。
    搜索更多联机帮助操作:
    查看详细信息
    将异常详细信息复制到剪贴板
      

  2.   

    Bitmap im1 = new Bitmap(im); 报错???
    肯看im为什么为空
      

  3.   

    什么意思?
    好象是  Bitmap im = new Bitmap(pictureBox1.Image);    抱错!
      

  4.   

    picturebox1  中有图像 
      

  5.   

    我原封不动的粘贴了你的代码,没有任何问题,还是看看pictureBox1中是否有图像