日期:2014-05-18  浏览次数:20729 次

这个C#程序哪出问题了?
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;
  }
  }
}

------解决方案--------------------
没有问题啊,只是处理有点慢.你是想进行图片的特效处理吧?
------解决方案--------------------
Bitmap im1 = new Bitmap(im); 报错???
肯看im为什么为空
------解决方案--------------------
picturebox中有图像吗?
------解决方案--------------------
探讨
picturebox中有图像吗?

------解决方案--------------------
检查一下picturebox啊
探讨
引用:
picturebox中有图像吗?

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