Draw in a picturebox [solved]
Posted
#1
(In Topic #552)
Trainee
Code
Private myPlayer As New MediaPlayer As "Player"
'=============================================================================
Public Sub Form_Open()
myPlayer.URL = "v4l2:///dev/video0"
myPlayer.Play()
End
'=============================================================================
Public Sub Form_Close()
myPlayer.Stop()
End
'=============================================================================
Public Sub TheButton_Click()
Dim theImage As Image = myPlayer.Video.Image
theImage.Save(Application.Path &/ Format(Now, "yyyymmdd_hhnnss") & ".jpg"
ThePictureBox.Image = theImage
End
Is there a way to draw a 2 lines (a crosshair) in the Picturebox or put a crosshair in a transparent Drawingarea on top of the Picturebox?
None of my attempts have been successful so far.
Posted
Regular

Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Trainee
Code
Dim theImage As Image = myPlayer.Video.Image
theImage.Save(Application.Path &/ Format(Now, "yyyymmdd_hhnnss") & ".jpg"
ThePictureBox.Image = theImage
Paint.Begin(theImage)
Paint.LineWidth = 1
Paint.Rectangle(10, 10, 100, 100)
Paint.Stroke
Paint.End
The problem is that I was thinking wrong. theImage is just one image but I want to get a haircross over the live videofeed. It works in opencv and python using cv2.line(…) but as I understand Gambas don't support opencv (correct me if I'm wrong). Gambas is so much nicer to work in so I would rather solve it here. I tried to put FMain form over the mediaplayer form and made it transparent. So far so good but as soon as I try to paint something in an picturebox in the Fmain form the whole picturebox went grey and not transparent. Is there some way to draw/paint a line in some control but leave the background transparent?
Posted
Regular

Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Trainee
Code
Private myPlayer As New MediaPlayer As "Player"
'=============================================================================
Public Sub Form_Open()
'--- Opens a mediaplayer window with live video stream ---
myPlayer.URL = "v4l2:///dev/video0"
myPlayer.Play()
' --- Make the FMain window transparent so you can see the
' --- mediaplayer window behind.
FMain.Transparent = True
End
'=============================================================================
Public Sub Button2_Click()
ThePictureBox.Cached = True ' -- Get "Cannot paint outside of Draw event handler i FMain:22" without cached=True
Paint.Begin(ThePictureBox)
Paint.LineWidth = 1
Paint.Rectangle(10, 10, 100, 100)
Paint.Stroke
Paint.End
End
'=============================================================================
Public Sub Form_Close()
myPlayer.Stop()
End
'=============================================================================
The whole FMain is transparent including the picturebox in FMain. As soon as I hit the Button2 the picturebox turns grey and draw a rectangle in the grey picturebox.
Posted
Regular

Code (gambas)
- ThePictureBox.Background = Color.Transparent
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Regular

Code (gambas)
- '=============================================================================
- '--- Opens a mediaplayer window with live video stream ---
- myPlayer.URL = "v4l2:///dev/video0"
- myPlayer.Play()
- ' It locks the Events of the "DrawingArea":
- ' It unlocks the Events of the "DrawingArea":
- ' It stimulates the redraw of the DrawingArea:
- DrawingArea1.Refresh
- ' It draws a simple crosshair:
- With Paint
- .Brush = .Color(Color.Red)
- .LineWidth = 2.0
- .MoveTo(DrawingArea1.W * 0.25, DrawingArea1.H / 2)
- .LineTo(DrawingArea1.W * 0.75, DrawingArea1.H / 2)
- .MoveTo(DrawingArea1.W / 2, DrawingArea1.H * 0.25)
- .LineTo(DrawingArea1.W / 2, DrawingArea1.H * 0.75)
- .Stroke
- .End
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Trainee
Posted
Regular

I use picture boxes for any dynamic elements, e.g. ones that move or are re-drawn frequently, so that I do not need to redraw the background elements each time.
If you are getting a new frame all the time though I guess that is not a really big consideration.
1 guest and 0 members have just viewed this.



