能不能直接操作image,给它加入白色的边框,而图片相应缩小不被裁剪掉呢???
本来我用了一个ASPJPEG控件可以实现加入白色边框,不过感觉效率不高,能不能用C#实现此功能 ?
我以前的代码是:
jpeg.Open(tempfile);
//加白边
jpeg.Crop( -20, 0, jpeg.Width, jpeg.Height + 20);
//下面三句是以前的先把图片存到一个文件,然后再读到Image对象里
//jpeg.Save(tempfile);
//jpeg.Close(); 
//jp=Image.FromFile(tempfile);
//把上面三句换为下面的代码出错意思是jpeg.Binary返回的是object类型,不能转为stream类型
jp=Image.FromStream(jpeg.Binary);
怎么实现转换呢?

解决方案 »

  1.   

    用GDI+很容易啊,将图片缩小一定比例,然后再生成一个新的图像,在周围画上框,使用Image对像呀BitMap对像中的方法
      

  2.   

    //边宽
    int borderWidth = 2;
    //边框颜色
    Color borderColor = Color.White;
    Image img = Bitmap.FromFile("yourImageName.jpg");
    int width = img.Width + 2 * borderWidth;
    int height = img.Height + 2 * borderWidth;
    Bitmap bmp = new Bitmap(width, height);
    Graphics g = Graphics.FromImage(bmp);
    g.DrawImage(img, borderWidth, borderHeight);
    g.DrawRectangle(new Pen(borderColor, borderWidth), 0, 0, width, height);
    bmp.Save("yourFileName");
    g.Dispose();
      

  3.   

    楼主试试帮我看看我这个问题:
    http://community.csdn.net/Expert/topic/4515/4515514.xml?temp=.3384058
      

  4.   

    johnsuna(缘来是e)的办法应该可行。