图片截取 写字"/>
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图片截取 写字
发布评论