ASP.NET MVC 网站开发总结(七)——C#操作图片:多张图的拼接(旋转)

时间:2022-02-20 15:00:47

其实用C#来操作图片的拼接就是在用Graphic画图。个人感觉还是挺有趣的,各种类库提供了丰富多彩的功能。

源代码(移植到一个简单的C#程序中,并没有放在ASP.NET项目中):

using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging; namespace Test
{
class Program
{ static void Main(string[] args)
{ Image img = new Bitmap(new Bitmap("model1.png"), , );//加载图片
Graphics g = Graphics.FromImage(img);//将图片转化Graphics
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;//加上抗锯齿效果
//
Point[] destPoints1 = {
new Point(, ),//图片左上点
new Point(, ),//图片右上点
new Point(, ),//图片左下点
};
g.DrawImage(new Bitmap("img1.jpg"), destPoints1);//按指定的顶点画图
g.DrawLines(new Pen(Brushes.Gray), new Point[] {
new Point(, ),
new Point(, ),
new Point(, ),
new Point(, ),
new Point(, ),
});//画线,描绘img1图片的边界 Point[] destPoints2 = {
new Point(, ),
new Point(, ),
new Point(, )
};
g.DrawImage(new Bitmap("img1.jpg"), destPoints2);
g.DrawLines(new Pen(Brushes.Gray), new Point[] {
new Point(, ),
new Point(, ),
new Point(, ),
new Point(, ),
new Point(, ),
});
g.FillRectangle(Brushes.Gray, , , , );//画矩形
g.DrawImage(new Bitmap("img1.jpg"), , , , );//直接按指定长宽画图
img.Save("test1.png");//保存为图片
img.Dispose();//显示释放资源
g.Dispose();
}
}
}

效果图:

ASP.NET MVC 网站开发总结(七)——C#操作图片:多张图的拼接(旋转)

  此次知识分享就到这,敬请期待下一次的分享。^_^

<我的博客主页>:http://www.cnblogs.com/forcheng/

<Wing工作室主页>:http://www.wingstudio.org/