首页 > 开发 > 综合 > 正文

在图片上写字 (C#)

2024-07-21 02:19:37
字体:
来源:转载
供稿:网友
下面的代码实现了从剪贴板取出图片,然后写上字,保存到文件
image bmap;
idataobject data = system.windows.forms.clipboard.getdataobject();
bmap = (image)(data.getdata(typeof(system.drawing.bitmap)));
graphics g = graphics.fromimage(bmap);

solidbrush drawbrush = new solidbrush(color.red);
font drawfont = new font("arial", 10, fontstyle.bold, graphicsunit.millimeter);
int xpos = bmap.height - ( bmap.height-25 );
int ypos = 3;

g.drawstring ("zydzydyzydydydyyydydy", drawfont, drawbrush, xpos, ypos);

string spicpath = "d://filename.jpg";
string sprefix = "d://xxx";

image smbmap ;

smbmap = bmap.getthumbnailimage(bmap.width, bmap.height, null, system.intptr.zero);

smbmap.save(spicpath, system.drawing.imaging.imageformat.jpeg);

bmap.save(sprefix + ".jpg", system.drawing.imaging.imageformat.jpeg);
bmap = null;
smbmap = null;

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表