只需要学会一门语言就能前后端通吃.
import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio教程 简码编程www.jianma123.com";right=755;bottom=623)
winform.add(
button={cls="button";text="Button";left=581;top=502;right=660;bottom=554;z=2};
custom={cls="custom";text="自定义控件";left=17;top=373;right=504;bottom=606;edge=1;z=5};
editCode={cls="edit";left=580;top=452;right=660;bottom=481;edge=1;z=4};
editLog={cls="edit";left=17;top=13;right=742;bottom=362;autohscroll=false;edge=1;multiline=1;vscroll=1;z=3};
picturebox={cls="picturebox";left=580;top=399;right=660;bottom=435;edge=1;z=1}
)
/*}}*/
class cyweb{
ctor(width=80,height=36,size=4){
..math.randomize();
this.width = width; //生成图片宽
this.height = height; //图片高
this.size = size; //验证码位数
this.charset = "abcdefghkmnprstuvwxyz0123456789"; //验证码随机值
this.code = ..string.random(this.size,this.charset);
};
get = function(){
return this.code;
}
color = function(n,m){
var x = ..string.format("%02X",..math.random(n,m));
var y = ..string.format("%02X",..math.random(n,m));
var z = ..string.format("%02X",..math.random(n,m));
var ys = "0xFF"++tostring(x)++tostring(y)++tostring(z);
return tonumber(ys);
}
creat = function(){
import gdip;
var bmp = gdip.bitmap(this.width,this.height);
var graphics = bmp.graphics;
//画背景
var brush = gdip.solidBrush(this.color(157,255));
graphics.fillRectangle(brush,0,0,this.width,this.height);
//画线
for(i=0;6;1){
var pen = gdip.pen(this.color(0,156), 1, 2/*_GdipUnitPixel*/ );
graphics.drawLine(pen,..math.random(0,this.width),..math.random(0,this.height),..math.random(0,this.width),..math.random(0,this.height));
}
//杂色
for(i=0;60;1){
var brush = gdip.solidBrush(this.color(200,255));
var family = gdip.family("Tahoma");
var strformat = gdip.stringformat ();
strformat.align = 0/*_GdipStringAlignmentNear*/;
var curFont = family.createFont(..math.random(1,15),, 2/*_GdipUnitPixel*/);
graphics.smoothingMode = 4/*_GdipSmoothingModeAntiAlias*/ ;
graphics.textRenderingHint = 3/*_GdipTextRenderingHintAntiAliasGridFit*/;
rclayout = gdip.RECTF();
rclayout.x = ..math.random(0,this.width)
rclayout.y = ..math.random(0,this.height)
graphics.drawString("*",curFont, rclayout, strformat,brush);
}
var x = this.width/4;
var tab = ..string.split(this.code);
for(i=1;#tab;1){
var brush = gdip.solidBrush(this.color(0,156));
var family = gdip.family("Tahoma");
var strformat = gdip.stringformat ();
strformat.align = 0/*_GdipStringAlignmentNear*/;
var curFont = family.createFont(26,, 2/*_GdipUnitPixel*/);
graphics.smoothingMode = 4/*_GdipSmoothingModeAntiAlias*/ ;
graphics.textRenderingHint = 3/*_GdipTextRenderingHintAntiAliasGridFit*/;
rclayout = gdip.RECTF();
rclayout.x = x*(i-1)+..math.random(1,3);
rclayout.y = (this.height-30)/2.4;
graphics.drawString(tab[i],curFont, rclayout, strformat,brush);
}
var data = ..raw.tostring(bmp.saveToBuffer("*.jpg",50))
bmp.dispose();
import crypt.bin;
//返回用于网页的base64图像和用于软件控件的图像
return 'data:image/jpg;base64,'++crypt.bin.encodeBase64(data),data;
}
}
import web.form;
var wb = web.form(winform.custom);
winform.button.oncommand = function(id,event){
var va = cyweb();
var imgBase64,imgObj = va.creat();
var imgCodeTxt = va.get();
winform.editLog.text = imgBase64;
winform.picturebox.image = imgObj;
winform.editCode.text = imgCodeTxt;
wb.html = `
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
<body>
<div class="captcha-img">
<img id="captchaPic" src="`++imgBase64++`">
</div>
</body>
</html>
`;
}
winform.show();
win.loopMessage();