plus控件实现手写签名板
By
nod32
at 2022-03-27 • 0人收藏 • 887人看过
import win.ui; /*DSG{{*/ var winform = win.form(text="aardio form";right=904;bottom=602) winform.add( button={cls="button";text="清空";left=289;top=489;right=571;bottom=558;z=1}; button2={cls="button";text="保存";left=598;top=490;right=808;bottom=558;z=3}; plus={cls="plus";left=66;top=49;right=821;bottom=447;bgcolor=16777215;notify=1;z=2}; plus2={cls="plus";left=71;top=473;right=254;bottom=577;foreRepeat="scale";z=4} ) /*}}*/ import gdip; import gdip.bitmap import gdip.snap; //图形对象graphics(可以看作是画板) var graphics = gdip.graphics( winform.plus ) //加上抗锯齿功能 graphics.smoothingMode = 4/*_GdipSmoothingModeAntiAlias*/ ; var penColor = 0xFF000000;//线颜色 var penWidth = 8;//线宽 var startcap = 2;//起点线帽,指定线帽后画笔宽度为线帽宽度 var endcap = 2;//终端线帽,指定线帽后画笔宽度为线帽宽度 var drawData; //点坐标数组 var undoArr = {};//存放每一次鼠标弹起后的点坐标信息 winform.button.oncommand = function(id,event){ //winform.redraw() graphics.clear(0xFFFFFFFF) ;//清空画板,并填充指定颜色 undoArr = {}; } //定义鼠标初始坐标 var x1 = 0 var y1 = 0 winform.plus.onMouseDown = function(wParam,lParam){ x1,y1 = win.getMessagePos(lParam); drawData = {::POINTF(x1,y1)} } winform.plus.onMouseMove = function(wParam,lParam){ if( wParam & 0x1/*_MK_LBUTTON*/ ){ var x2,y2 = win.getMessagePos(lParam); table.push(drawData,::POINTF(x2,y2) ) var pen = gdip.pen( penColor, penWidth,2/*_GdipUnitPixel*/); pen.startCap = startcap pen.endCap = endcap graphics.drawLine( pen, x1, y1, x2, y2) x1 = x2; y1 = y2; pen.delete() } } winform.plus.onMouseUp = function(wParam,lParam){ //var x,y = win.getMessagePos(lParam); table.push(undoArr,drawData); drawData = null; } //winform.plus.modifyStyle(, 0x2000000/*_WS_CLIPCHILDREN*/) //winform.modifyStyle(, 0x2000000/*_WS_CLIPCHILDREN*/ ) winform.button2.oncommand = function(id,event){ var bitmap = gdip.snap(winform.plus.hwnd) var old = winform.plus2.setForeground(bitmap,,true) //显示到plus2上 if( old ) old.dispose(); bitmap.save("c:\截图.jpg",80) //保存位图 } //重绘 winform.plus.onDrawForegroundEnd = function(graphics,rc){ var pen = gdip.pen( penColor, penWidth,2/*_GdipUnitPixel*/); pen.startCap = startcap pen.endCap = endcap if(#undoArr>0){ for(i=1;#undoArr;1){ for(j=2;#undoArr[i];1){ graphics.drawLine(pen,undoArr[i][j-1].x,undoArr[i][j-1].y,undoArr[i][j].x,undoArr[i][j].y); } } } pen.delete() } winform.show(); win.loopMessage();
实现了在plus上签名并保存成位图,但有个问题,当窗体尺寸调整或最小化恢复后,plus上的graphics会丢失,这个怎么解决??
↑↑↑↑↑ 上面的问题,参考官方的画板解决了
2 个回复 | 最后更新于 2022-03-20
登录后方可回帖
重绘啊
新建工程里有小画板, 自己看代码