Link to home
Start Free TrialLog in
Avatar of udk1
udk1Flag for Germany

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
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

.Net can paint one picture over another with transparency so putting the image to be scaled over the "dots" isn't a problem.  Then you can use the MouseDown/MouseMove/MouseUp events to determine where the user has clicked.  Are the dots in a fixed (calculateable) positions?...or do you need to analyze the background image to figure this out?  It isn't clear exactly how to implement the process you are describing goes.   This part is kinda vague:

  "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
Avatar of udk1

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
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.MouseEventArgs) Handles Panel1.MouseDown
        If e.Button = MouseButtons.Left Then
            prevClip = Cursor.Clip
            Cursor.Clip = Panel1.RectangleToScreen(New Rectangle(New Point(0, 0), Panel1.ClientSize))
            screenPtA = Panel1.PointToScreen(New Point(e.X, e.Y))
            screenPtB = screenPtA
            ControlPaint.DrawReversibleFrame(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.MouseEventArgs) Handles Panel1.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            ControlPaint.DrawReversibleFrame(New Rectangle(screenPtA, GetSize(screenPtA, screenPtB)), Color.Black, FrameStyle.Dashed)
            screenPtB = Panel1.PointToScreen(New Point(e.X, e.Y))
            ControlPaint.DrawReversibleFrame(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.MouseEventArgs) 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.DrawReversibleFrame(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.Width)
        End If
        If selectionArea.Height < 0 Then
            selectionArea.Y = selectionArea.Y + selectionArea.Height
            selectionArea.Height = Math.Abs(selectionArea.Height)
        End If

        ' convert the rectangle back to client coordinates
        selectionArea = Panel1.RectangleToClient(selectionArea)

        ' do something with it..
        PictureBox1.SuspendLayout()
        PictureBox1.Location = selectionArea.Location
        PictureBox1.Size = selectionArea.Size
        PictureBox1.ResumeLayout()
    End Sub

End Class
Avatar of udk1

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
"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...
Avatar of udk1

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
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.  =\
Avatar of udk1

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
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial