udk1
asked on
Picture Scaling by measuring clicked area
Hello Experts,
I would like to adapt the size of one picture depending on a special area of another one. In other words: one picture will be background. This picture has dots in it. Depending on the dot size an other picture (which will be displayed transparent over the background one) has to scaled. I think the dot has to be clicked to specify the search area and the color of the dot. Then getting the size of the dot. Depending on this size the second picture has to be resized.
Currently I do not have any idea how to start it. Which functions of the .NET Api will be suffcient?
Any ideas are welcome
udk
I would like to adapt the size of one picture depending on a special area of another one. In other words: one picture will be background. This picture has dots in it. Depending on the dot size an other picture (which will be displayed transparent over the background one) has to scaled. I think the dot has to be clicked to specify the search area and the color of the dot. Then getting the size of the dot. Depending on this size the second picture has to be resized.
Currently I do not have any idea how to start it. Which functions of the .NET Api will be suffcient?
Any ideas are welcome
udk
ASKER
Hello Idle Mind,
I tried to upload but failed with "Invalid Question value". It seems the system does not see this open question: if I choose to use "Pointer Question Wizzard" -> "Title Topic Area" is empty.
So I try it in words again:
The background of a Panel displays the picture.
Above there is a PictureBox. The size of the PictureBox Image has to be adapted to the size of the "current" white dot of the background image.
The background can have various dots. So best will be the dot has to be clicked once and the location and scaling size will be stored and then draging the picturebox near or upon this location it is resized.
udk1
I tried to upload but failed with "Invalid Question value". It seems the system does not see this open question: if I choose to use "Pointer Question Wizzard" -> "Title Topic Area" is empty.
So I try it in words again:
The background of a Panel displays the picture.
Above there is a PictureBox. The size of the PictureBox Image has to be adapted to the size of the "current" white dot of the background image.
The background can have various dots. So best will be the dot has to be clicked once and the location and scaling size will be stored and then draging the picturebox near or upon this location it is resized.
udk1
Ok...so we have some dots on the PANEL. The user clicks and drags from one dot to another? Then the PICTUREBOX is resized to be the same size as what the user dragged? Does the "new size" need to be "snapped" to the "center" of these dots?...or do you want it to just size to exactly what the user dragged?
It sounds like you need a basic "rubberband" operation on a Panel:
Public Class Form1
Private prevClip As Rectangle
Private screenPtA, screenPtB As Point
Private Sub Panel1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles Panel1.MouseDown
If e.Button = MouseButtons.Left Then
prevClip = Cursor.Clip
Cursor.Clip = Panel1.RectangleToScreen(N ew Rectangle(New Point(0, 0), Panel1.ClientSize))
screenPtA = Panel1.PointToScreen(New Point(e.X, e.Y))
screenPtB = screenPtA
ControlPaint.DrawReversibl eFrame(New Rectangle(screenPtA, GetSize(screenPtA, screenPtB)), Color.Black, FrameStyle.Dashed)
End If
End Sub
Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles Panel1.MouseMove
If e.Button = Windows.Forms.MouseButtons .Left Then
ControlPaint.DrawReversibl eFrame(New Rectangle(screenPtA, GetSize(screenPtA, screenPtB)), Color.Black, FrameStyle.Dashed)
screenPtB = Panel1.PointToScreen(New Point(e.X, e.Y))
ControlPaint.DrawReversibl eFrame(New Rectangle(screenPtA, GetSize(screenPtA, screenPtB)), Color.Black, FrameStyle.Dashed)
End If
End Sub
Private Sub Panel1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles Panel1.MouseUp
If e.Button = MouseButtons.Left Then
Cursor.Clip = prevClip
screenPtB = Panel1.PointToScreen(New Point(e.X, e.Y))
Dim r As Rectangle = New Rectangle(screenPtA, GetSize(screenPtA, screenPtB))
ControlPaint.DrawReversibl eFrame(r, Color.Black, FrameStyle.Dashed)
RectangleSelected(r)
End If
End Sub
Private Function GetSize(ByVal ptA As Point, ByVal ptB As Point) As Size
Return New Size(ptB.X - ptA.X, ptB.Y - ptA.Y)
End Function
Private Sub RectangleSelected(ByVal selectionArea As Rectangle)
' normalize the rectangle
If selectionArea.Width < 0 Then
selectionArea.X = selectionArea.X + selectionArea.Width
selectionArea.Width = Math.Abs(selectionArea.Wid th)
End If
If selectionArea.Height < 0 Then
selectionArea.Y = selectionArea.Y + selectionArea.Height
selectionArea.Height = Math.Abs(selectionArea.Hei ght)
End If
' convert the rectangle back to client coordinates
selectionArea = Panel1.RectangleToClient(s electionAr ea)
' do something with it..
PictureBox1.SuspendLayout( )
PictureBox1.Location = selectionArea.Location
PictureBox1.Size = selectionArea.Size
PictureBox1.ResumeLayout()
End Sub
End Class
It sounds like you need a basic "rubberband" operation on a Panel:
Public Class Form1
Private prevClip As Rectangle
Private screenPtA, screenPtB As Point
Private Sub Panel1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse
If e.Button = MouseButtons.Left Then
prevClip = Cursor.Clip
Cursor.Clip = Panel1.RectangleToScreen(N
screenPtA = Panel1.PointToScreen(New Point(e.X, e.Y))
screenPtB = screenPtA
ControlPaint.DrawReversibl
End If
End Sub
Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse
If e.Button = Windows.Forms.MouseButtons
ControlPaint.DrawReversibl
screenPtB = Panel1.PointToScreen(New Point(e.X, e.Y))
ControlPaint.DrawReversibl
End If
End Sub
Private Sub Panel1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse
If e.Button = MouseButtons.Left Then
Cursor.Clip = prevClip
screenPtB = Panel1.PointToScreen(New Point(e.X, e.Y))
Dim r As Rectangle = New Rectangle(screenPtA, GetSize(screenPtA, screenPtB))
ControlPaint.DrawReversibl
RectangleSelected(r)
End If
End Sub
Private Function GetSize(ByVal ptA As Point, ByVal ptB As Point) As Size
Return New Size(ptB.X - ptA.X, ptB.Y - ptA.Y)
End Function
Private Sub RectangleSelected(ByVal selectionArea As Rectangle)
' normalize the rectangle
If selectionArea.Width < 0 Then
selectionArea.X = selectionArea.X + selectionArea.Width
selectionArea.Width = Math.Abs(selectionArea.Wid
End If
If selectionArea.Height < 0 Then
selectionArea.Y = selectionArea.Y + selectionArea.Height
selectionArea.Height = Math.Abs(selectionArea.Hei
End If
' convert the rectangle back to client coordinates
selectionArea = Panel1.RectangleToClient(s
' do something with it..
PictureBox1.SuspendLayout(
PictureBox1.Location = selectionArea.Location
PictureBox1.Size = selectionArea.Size
PictureBox1.ResumeLayout()
End Sub
End Class
ASKER
Hello,
your solution mets nearly the current state of my development. If I click into the panel the picturebox moves to the point I've clicked to. Now I have the problem: how can I access to the clicked area of the background image (the dot), analyse the size of this dot and adapt the size of the Image displayed by the PictureBox and not only the size of the PictureBox.
Hopefully you can do this magic again to get a solution of your hat...
Best regards
udk
your solution mets nearly the current state of my development. If I click into the panel the picturebox moves to the point I've clicked to. Now I have the problem: how can I access to the clicked area of the background image (the dot), analyse the size of this dot and adapt the size of the Image displayed by the PictureBox and not only the size of the PictureBox.
Hopefully you can do this magic again to get a solution of your hat...
Best regards
udk
"how can I access to the clicked area of the background image (the dot), analyse the size of this dot and adapt the size of the Image displayed by the PictureBox and not only the size of the PictureBox."
To even begin to help with this we would need to see your image of "dots"...
Is it possible to generate this "dot background" using code at run-time? You could use the Panels Paint() event to paint the circles at run-time. Then you wouldn't necessarily need to analyze any images to figure out what was clicked...
To even begin to help with this we would need to see your image of "dots"...
Is it possible to generate this "dot background" using code at run-time? You could use the Panels Paint() event to paint the circles at run-time. Then you wouldn't necessarily need to analyze any images to figure out what was clicked...
ASKER
Hello Idle Mind,
the background picture of the panel is a raidograph of the bit and the picturebox contains a artifical tooth.
The radigraph is not linear scaled. While taking the photo some steel balls of the same size are fixed in the mouth. In the picture they appear as dots with different size then. This size of this dots then is to be used to get the correct scaling of the tooth. So the dots are given fix.
This is done in reality with the help of a template of dots with different size on a transparency which is layed over the original radiograph to get a estimation of the scaling to be used.
Now it becomes more real?
Best regards
udk
the background picture of the panel is a raidograph of the bit and the picturebox contains a artifical tooth.
The radigraph is not linear scaled. While taking the photo some steel balls of the same size are fixed in the mouth. In the picture they appear as dots with different size then. This size of this dots then is to be used to get the correct scaling of the tooth. So the dots are given fix.
This is done in reality with the help of a template of dots with different size on a transparency which is layed over the original radiograph to get a estimation of the scaling to be used.
Now it becomes more real?
Best regards
udk
It definitely helps with a mental "big picture" of what you are trying to achieve...unfortunately I think I would need to see you actually doing it in person to be of real help. =\
ASKER
Hello Idle Mind,
at least the problem for me is to access to the background picture at the point clicked and check whether there is a filled white circle and get the size of this circle.
How can I access the color of a specific pixel and access the neighbours ot this dot in all directions until the color changes. Then with the number of pixels in each direction I think I could exactly evaluate the circle dimensions. Which would be the used to callculate the scaling factor and then to resize the picturebox with no further problems.
So as long as I'm not familar with the .NET API I'm not able to do this.
Can you help me for this first step?
Thank you in advance
udk
at least the problem for me is to access to the background picture at the point clicked and check whether there is a filled white circle and get the size of this circle.
How can I access the color of a specific pixel and access the neighbours ot this dot in all directions until the color changes. Then with the number of pixels in each direction I think I could exactly evaluate the circle dimensions. Which would be the used to callculate the scaling factor and then to resize the picturebox with no further problems.
So as long as I'm not familar with the .NET API I'm not able to do this.
Can you help me for this first step?
Thank you in advance
udk
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
"I think the dot has to be clicked to specify the search area and the color of the dot. Then getting the size of the dot. Depending on this size the second picture has to be resized."
A picture is worth a thousand words. Can you upload some pictures to ee-stuff?
http://www.ee-stuff.com