我有个控件是从摄像头读取图像的,并显示图像,现在要做一个拖动小窗口,可以将图像中的人物脸部圈住,然后抓取图像,请问该如何处理呢?
我有个控件是从摄像头读取图像的,并显示图像,现在要做一个拖动小窗口,
可以将图像中的人物脸部圈住,然后抓取图像,请问该如何处理呢?
现在不清楚如何做这个浮动的窗口?
用一般控件好像不能在另一个控件上面停留。
请大家给个建议。
[解决办法]
- VB code
'''用摄像头控件生成临时图片,再将临时图片读取到Picture控件'''窗体通用声明中自定义用户数据结构 Private Type POINTAPI x As Long y As Long End TypeDim sPos As POINTAPI '''这句不用解释了吧'''一个Picture 控件'''一个Label 控件 (控件名:L)'''在Label的MouseDown的事件中将我们获得的坐标Private Sub L_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)If Button = 1 Then sPos.x = x sPos.y = yEnd IfEnd Sub'''这个也不用解释了吧o(∩_∩)o...Private Sub L_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)If Button = 1 And L.top >= 0 And L.left >= 0 And L.top <= Picture1.ScaleHeight - L.Height And L.left <= Picture1.ScaleWidth - L.Width Then L.top = L.top + (y - sPos.y) \ 15 L.left = L.left + (x - sPos.x) \ 15 L.Refresh If L.top < 0 Then L.top = 0 If L.left < 0 Then L.left = 0 If L.top > Picture1.ScaleHeight - L.Height Then L.top = Picture1.ScaleHeight - L.Height If L.left > Picture1.ScaleWidth - L.Width Then L.left = Picture1.ScaleWidth - L.WidthEnd IfEnd Sub'''再添加一个Picture2用来显示截取的图像Private Sub L_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)If Button = 1 Then Dim CurrentDc As Long Dim lHight, lWidth As Long selStartPos.x = L.left selStartPos.y = L.top selEndPos.x = L.left + (L.Width) selEndPos.y = L.top + (L.Height) lWidth = Abs((selStartPos.x - selEndPos.x)) lHight = Abs((selStartPos.y - selEndPos.y)) Picture2.Cls BitBlt Picture2.hdc, 0, 0, lWidth, lHight, _ Picture1.hdc, selStartPos.x, selStartPos.y, SRCCOPY Picture2.Refresh 'Exit SubEnd IfIf MsgBox("确定要截取并保存该部分图像吗?", 64 + vbYesNo, "提示") = vbYes Then If Text2.Text = "" Then MsgBox "货号-不能为空!", 64, "提示" Text2.SetFocus Exit Sub End If SavePicture Picture2.Image, VB.App.Path & "\test.bmp" FileCopy VB.App.Path & "\test.bmp", 你的变量 & "\" & Text2.Text & ".jpg"End IfEnd Sub
[解决办法]
很简单,放一个label,背景透明
在label1_MouseMove事件中
Picture2.PaintPicture Picture1.Picture, 0, 0, , , Label1.Left, Label1.Top, Label1.Width, Label1.Height
[解决办法]
抓取图像
Dim capCopy As Long
capCopy = SendMessage(capHwnd, WM_CAP_EDIT_COPY, 0, 0)
Picture1.Picture = Clipboard.GetData