纯属抛砖引玉,各位大佬有更优雅的方法欢迎在楼层交流;
打水印之前:
![](https://aardio.online/upload/files/20240526/1716733202.png)
import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio form";right=759;bottom=469)
winform.add()
/*}}*/
import gdip;
import gdip.graphics;
import fsys.dlg
printImageText = function(imgBuff,text,x,y,width,heigt,color,fontStyle,family,outPath){
var img = gdip.image(imgBuff)
var graphics = gdip.graphics.fromImage(img)
//创建刷子
var brush = gdip.solidBrush(color);
//创建FontFamily
var family = gdip.family(family);
//创建stringFormat
var strformat = gdip.stringformat ( );
//设置样式
strformat.align = 0/*_GdipStringAlignmentNear*/;
//创建Font
var curFont = family.createFont( 15,fontStyle, 2/*_GdipUnitPixel*/)
//设置文字区域
rclayout = gdip.RECTF(img);
rclayout.x = x
rclayout.y = y
rclayout.right = width//在这里指的是宽度
rclayout.bottom = heigt //在这里指的是高度
graphics.drawString( text, curFont, rclayout, strformat,brush);
//删除所有GDI+对象
brush.delete()
curFont.delete()
strformat.delete();
family.delete();
img.save(outPath);
img.dispose();
}
winform.show();
var path = fsys.dlg.save("*.jpg|*.jpg|*.jpeg|*.jpeg|*.jfif|*.jfif|*.png|*.png||",,,winform)
if(path){
printImageText("C:\Users\XZ\Desktop\1.png","Hellow world! 测试样式",150,300,100,100,0xFF0089E4,3,"宋体",path)
}
win.loopMessage();
运行时会弹出选择文件位置的框,填一下文件名就好;
![](https://aardio.online/upload/files/20240526/1716733320.png)