模拟鼠标拖动plus前景图片调整图像显示区域
By
admin
at 2018-05-12 • 0人收藏 • 1459人看过
基本算是花了一天时间实现的
准备用于摄像头图像显示区域调整上面,这个是简易版功能
import win.ui; /*DSG{{*/ var winform = win.form(text="鼠标拖动图像调整显示区域测试";right=639;bottom=377) winform.add( plus={cls="plus";left=126;top=102;right=490;bottom=268;border={color=-16777216;width=1};clipBk=false;clipch=1;foreRepeat="center";notify=1;z=1} ) /*}}*/ var bmp = gdip.bitmap( "http://bbs.aardio.com/data/attachment/forum/201804/28/234719vy3uyoqq65bb22lb.jpg.thumb.jpg" ); //定义显示图像的左上点初始坐标 var leftUpX = (bmp.width-winform.plus.width)/2; var leftUpY = (bmp.height-winform.plus.height)/2; //设置图像显示区域 function 图像调整(){ var posX,posY = -leftUpX,-leftUpY; var moveImg = function(graphics,x=0,y=0){ //X轴调整 if(x>=0){ if( posX>=0 ){ } else { posX = posX + x; if(posX>0) posX = 0; }; }else { if( posX <= (winform.plus.width-bmp.width) ){} else { posX = posX + x; if(posX <= (winform.plus.width-bmp.width)) posX = winform.plus.width-bmp.width; } } //Y轴调整 if(y>=0){ if( posY>=0 ){ } else { posY = posY + y; if( posY>=0 ) posY = 0; }; }else { if( posY<=(winform.plus.height - bmp.height) ){} else { posY = posY + y; if( posY<=(winform.plus.height - bmp.height) ) posY = winform.plus.height - bmp.height; } } graphics.drawImage( bmp,posX,posY); } return moveImg; } moveImg = 图像调整(); var startX,startY; var drawX,drawY = 0,0; winform.plus.onMouseDown = function(wParam,lParam){ winform.plus.capture = true; startX,startY = ..win.getMessagePos(lParam); win.ui.waitCursor(true,::User32.LoadCursor(null,0x7F86/*_IDC_SIZEALL*/)); } winform.plus.onMouseClick = function(wParam,lParam){ winform.plus.capture = false; win.ui.waitCursor(false); } winform.plus.onMouseMove = function(wParam,lParam){ if( wParam & 0x1/*_MK_LBUTTON*/ ){ var x,y = win.getMessagePos(lParam); drawX = x-startX; drawY = y-startY; winform.plus.redraw(); startX,startY = x,y; } } //winform.plus.background = 0xFFFFFFFF; winform.plus.onDrawContent = function(graphics,rc){ moveImg(graphics,drawX,drawY); } winform.show() win.loopMessage();
1 个回复 | 最后更新于 2018-05-13
登录后方可回帖
整合到halcon摄像头里去了,plus自绘图像和摄像头图像区域设置,方向刚好相反的,
顺手加了摄像头的一些东西。
这里需要注意:
上面获取check的部分,需要放置到halcon操作摄像头操作外面,要不然可能正在操作摄像头过程中变动check导致内存释放错误而崩溃,放到外面就是类似异步调整了。