OpenFileDialog openfile = new OpenFileDialog();
                        openfile.Filter = "Bmp Picture(*.*)|*.bmp";
                        if (openfile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            IsPictureImported = true;                            Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
                            Image img = new Bitmap(openfile.FileName);
                            img = DeleteBlankArea(img);
}
从文件读取了一张图片,请问DeleteBlankArea()怎么写呢,要去掉图片四周的空白部分。初步想法是四个双重循环,用像素检测出上下左右最初有图像的未知a,b,c,d.可是不知道怎么把这一部分另存为图片。或者有更好的处理办法?

解决方案 »

  1.   

    用picturebox显示吧
      if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    //openFileDialog1.Filter = "*.bmp|*.gif|*.jpg|*.*";
                    string filename = openFileDialog1.FileName;
                    Image img = Image.FromFile(filename);
                    pictureBox1.Image = img;
                }
    这样就行了,调整picturebox的缩放模式属性为stretchimage啊
      

  2.   

    扫描每一行,直到发现第一个不是全白的行。记录此时的白色行高。转90度,再记录,直至转了360度。这时候就能知道上下左右的白边宽度分别是多少了。DrawImage到一个新Bitmap即可,目标区域就是切掉白边后的长宽。
      

  3.   

    图片格式问题吧,用gif格式的应该能解决你说的问题
      

  4.   

    试试 Bitmap.MakeTransparent(Color)