allow user to draw a polygon region over 2D image

Posted on 2009-02-15
Last Modified: 2012-06-21
I hope my Title was clear

Simply, I want to allow a user to create a colored region .... This could be done which ever way you feel is best of the following examples or suggest another way if you like

1> Allow user to click and place polygon points around an area creating the colored region area
NOTE: Opacity  of colored region should allow image beneath to still be seen.

2. Or, the user could click and drag a rectangle or square to desired size and shape over selected region ...

Or maybe you have a suggestion ...

Question by:vbMarkO
    LVL 2

    Expert Comment

    Which environment and what language do you want to use? I can give some pointers how to do it in Visual C++.
    LVL 6

    Expert Comment

    Do you need a (vb or ?) solution as the zone the question you have posted in implies?
    Assuming you need a vb solution and you are dealing with pictureboxes, you may use the
    region api to realize your task.

    Author Comment

    My Bad, I thought I posted this as Visual Basic 2008 Express so no C++ or C# ..... straight VB 2008

    OK for more details .... my image is in a Picture box ...

    If you need any other info just ask away :)


    Author Comment

    I am not sure what to ad to this to give it more attention but I will try ...

    I have a WInform with a panel (Panel1) on it
    Within the Panel1 is a Picturebox1
    In the PB is a Map image ......

    WHat I would like to do is be able to Draw out a region .... lik a polygon region or highlighted region of the image ....... I really like the idea of a polygonal low opacity region so that you can se what is under neath it but be allowed to manipulate the points or change the shape of the region ...

    I think you would know what I am talking about .... but if I need to find an example I can ....

    Oh by the way ... you are welcome to point me to a place where a Visual Basic 2008 example might be .... No C# please

    LVL 85

    Accepted Solution

    Hi again vbMarkO,

    Dragging a simple rectangle and allowing the map to show thru isn't that hard...but it gets a little trickier when you want to allow the user to resize/move them around.

    Will this be used in the app that you are developing in the other question I am helping you with?  If so, should the user be able to add "marks" inside the colored region?

    Food for thought...look at the solution I posted here:  (5th from the bottom)


    Author Comment

    Yes, you are correct the user should be able to place marks/points within rectangle area

    Ok, now about the other post solution .... the use of forms ...I assume this is the one you are referring to?

    Very smart, loved the concept, I can see real advantages to this ...... do you feel it the better solution than drawing then?
    LVL 85

    Expert Comment

    by:Mike Tomlinson have to make a design decision and there isn't a straight forward easy answer here....

    VB.Net does support transparency but it comes in different flavors.  =\

    (1) You can DRAW the transparent region onto your map but this is done by actually combining the map and the "overlay" into one NEW image.  The drawback here is that whenever you want to move and/or resize the region we have to start with the ORIGINAL image (have to store that somewhere) and combine it with the new position.  This is a costly operation and it may flicker ALOT as you resize/move the region.  Additionally, once the region is drawn, it will simply be an image which is unable to respond to user interaction.  We will have to manually do "hit-testing" as the mouse moves to see if we are over the region and change the mouse cursor and react accordingly.  This gets hard to manage real fast...especially since you have multiple types of "objects" in your space.  You have regions AND points to deal with.  It isn't impossible, though, and I have quite a few examples posted here at EE that you can play with.

    It's important to note that CONTROLS do not support TRUE transparency in VB.Net.  If you were to use a PictureBox or Panel to represent your Region, and then attempt to overlay it on the map PictureBox (by placing it above/over), you can't get the Region to be transparent and show the map underneath.

    You can, however, get a seperate WINDOW (form) to be transparent and show the window underneath.  This brings us to option #2.

    (2) Use "floating" forms to house the regions and allow us true transparency.  The advantage here is that we get the moving and resizing of the regions for almost free as forms allow themselves to be moved and/or resized already.  There are disadvantages too though.  We have to make sure that the forms are moved whenever the main form is moved so that they stay over the correct spots.  Additionally we must make sure that the user doesn't move/resize them outside the main form area.  Finally, since they are actually forms, when the user clicks on them to place a "mark", we will have to pass on that message to the main form so it reacts as if it was directly clicked on.

    As you can see...there isn't a perfect fit here.  The "crutch" being that the regions need to be transparent and .Net doesn't support that in a way that most developers like...

    Author Comment

    Idle MInd ... I have been giving this a lot of thought ...

    You said: " have to make a design decision "

    I am really impressed with the Form method .... and I will be going that way ....

    But, the Design decision you mentioned was in fact what I did .... after really deliberating both methods I am opting not to implement this at this time though as I feel the need to get the main purpose of the app finish and that is to collect crime data for a given area and display it.

    Thus I am accepting the Form method as the Solution ....

    On a side note ..... this form method has given me ideas of other uses .... for different apps

    Thank you for this input and sorry I was a little long in making this decision


    Author Closing Comment

    Great idea using Forms ..... has opened my mind to think out side of the box ... Thank You
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    No worries about the length of time...that means nothing to me.  My concern was making sure you knew the pros/cons of the two different methods.  =)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    The viewer will learn how to implement Singleton Design Pattern in Java.
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now