using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
namespace 转换
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {        }        private void button1_Click(object sender, EventArgs e)
        {
                        Bitmap bmp1;
            Bitmap bmp2;
                        string filename = @"C:\Documents and Settings\All Users\Documents\My Pictures\示例图片\Sunset.jpg";
            bmp1 = new Bitmap(filename);
            bmp2 = new Bitmap(6000, 6000, PixelFormat.Format24bppRgb);
                        int i =0; int j =0;
            for (int x=0; x<bmp1.Width; x++)
            {
                
                for (int y = 0; y <bmp1.Height; y++)
                {
                    Color c1 = bmp1.GetPixel(x, y);
                        bmp2.SetPixel(i,j,c1);
               
                   j++;                }
                i ++;
            }
                this.pictureBox1.Image = bmp2;
            }
       
    }
}
我做了个测试程序,可是总有问题!请高手帮忙解答一下,不胜感激啊!

解决方案 »

  1.   

    未处理 System.ArgumentOutOfRangeException
      Message="参数必须为正且小于高度。\r\n参数名: y"
      Source="System.Drawing"
      ParamName="y"
      StackTrace:
          错误是这样的,原图像是6000*6000像素的
      

  2.   

    j++
    这句加上校验,改成……
         if (j!=bmp1.Height )
                        {j++;}
    注:已经测试通过。但是你的双重循环如果图片过大,机器会倒。N*N次的循环,建议重新找算法或是解决方法。祝好运
      

  3.   

    我就奇怪,有了x和y,为什么还要用i和j里面连续对j进行递增,导致它会很大,超出bmp2的大小,所以出错最简单的改法就是用x和y替代i,j其实就是for (int y = 0; y <bmp1.Height; y++) 这行前面把j清零
      

  4.   

    因为我最终要做的是对原始图像间隔取点,所以会用x,y和i,j
    多谢帮助哦!