C# Graphics图片截取 写字

编程入门 行业动态 更新时间:2024-10-09 22:17:34

C# Graphics<a href=https://www.elefans.com/category/jswz/34/1770705.html style=图片截取 写字"/>

C# Graphics图片截取 写字

string GoldPath = @"F:\gold.jpg";
string NewJpgFile = @"E:\111\gold.jpg";
System.Drawing.Image image = System.Drawing.Image.FromFile(GoldPath);
Bitmap bitWaterMark = new Bitmap(1000, 1000);
Graphics g = Graphics.FromImage(bitWaterMark);
//指定颜色填充
g.Clear(System.Drawing.Color.White);
//写字
GraphicsText(g, "基准图", 5, 0, 20);
GraphicsText(g, "缺陷图", 455, 0, 20);Rectangle rectIn = new Rectangle(1000, 666, 200, 200);
Rectangle rectOut = new Rectangle(0, 100, 200, 400);
//图片截取
CutImg2Graphics(g, image, rectIn, rectOut);rectIn = new Rectangle(1500, 1500, 200, 200);
rectOut = new Rectangle(450, 100, 400, 400);
CutImg2Graphics(g, image, rectIn, rectOut);bitWaterMark.Save(NewJpgFile);
bitWaterMark.Dispose();
g.Dispose();
image.Dispose();/*
g--画布
image--被截取的图
rectInImg--截取图上的位置
rectInG--画布上的位置
*/public void CutImg2Graphics(Graphics g, System.Drawing.Image image, Rectangle rectInImg, Rectangle rectInG)
{g.DrawImage(image, rectInG, rectInImg, GraphicsUnit.Pixel);
}
/*
g--画布
str--字符串
x,y--坐标
FontSize--字体大小
*/
public void GraphicsText(Graphics g,string str,float x,float y,int FontSize=15)
{g.DrawString(str, new Font("宋体", FontSize, System.Drawing.FontStyle.Bold), System.Drawing.Brushes.Red, x, y);
}

更多推荐

C# Graphics图片截取 写字

本文发布于:2024-02-10 22:03:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1677536.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图片   Graphics

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!