Hotspots in .Net
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 43

Thread: Hotspots in .Net

Hybrid View

  1. #1
    Join Date
    Apr 2007
    Posts
    68

    Hotspots in .Net

    Hi All

    I am creating a Windows based application, my main screen is based on a picture, instead of using buttons, I would like to create hotspots on the picture for navigation, is this possible in the .net Windows application, this is not for the web.

    Cheers

    Djbel

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Hotspots in .Net

    You can load an image directly onto a form, or onto a picturebox control. Then, you can capture mouse clicks, and compare the location to 'spots' that you activate, and fire in the 'click event' and produce the action.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Apr 2007
    Posts
    68

    Re: Hotspots in .Net

    Hi dglienna

    Thanks for the reply. unfortuantly I am not exactly clear on what you mean. Do you mean have a set of cordinates for each area, then take the position of a mouse click and check if it is within a set of coordinates, if it is then fire a click event? If this is the case just got a couple of questions, how do I set up a coordinate location for an area on a picture and secondly how would I do this for complex shapes such as circles, ect?

    Cheers

    Djbell

  4. #4
    Join Date
    Dec 2003
    Location
    Northern Ireland
    Posts
    1,362

    Re: Hotspots in .Net

    It is going be a bit more complicated if you are using irregular shaped hotspots.

    Using the mouseup event will give you coordinates clicked in the picbox. You will need a way to determine which region the clicked coordinates are in.

    Rectangular and circular regions should be relatively easy. I would create a class for your regions containing the following vars: region_type (enum), parameter1, parameter2
    region_type specifies whether the region is circular or rectangular. If circular, parameter1 is midpoint of circle and parameter2 is radius. If rectangular, parameter1 is upper left corner and parameter2 is lower right.

    You will need a routine that accepts your coordinates, checks through your regions and calls the appropriate function (this could happen in the region class if you do it that way).

    ps: have you looked at WPF ? I think this can be done on a WPF form.
    Last edited by HairyMonkeyMan; December 22nd, 2008 at 05:40 AM.
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook


    0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010

  5. #5
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Hotspots in .Net

    Not with a class of shapes, if they are all the same size (within circle or square dim's)

    Gets more complex with different sized shape, though
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    Re: Hotspots in .Net

    IF you control the picture, there is a simple trick...Use the LSB of each color. This allows for 7 hotspots in an impage without ANY calculations.

    Stegography in action!!!!
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  7. #7
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Hotspots in .Net

    Which 7 are those?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    Re: Hotspots in .Net

    Quote Originally Posted by dglienna View Post
    Which 7 are those?
    Use a 24/32 bit format. Make sure the "real" picture has only EVEN color values (LSB or R,G,B are 0.)

    Now modify the picture to the the LSB to 001,010,011,100,101,110,111 (R,G,B) for seven different areas.

    Now when you geta click, look at a the pixel. Grab the LSB of R,G,B; combine. If 000 then not a hotspot, otherwise it is one of the 7...
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  9. #9
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Hotspots in .Net

    I made it even easier than that ...

    Because Pic2 is a background mask, and the user does not get to see it, i used all the greyscale bits, giving me 256 different regions. (&H00 - &HFF) ..

    I used white (&HFF) as the base region, or background, non hotspot. and painted each region needed as a hotspot with a different color.

    So for the first region i used black (&H00).. For region 2, I could have used the next color (&H01) but i jumped a few to visually show the different regions in the masked image. So region 2 is color 10 (&H0A), region 3 = 20 (&H14) .. etc

    Esentually you use each available color as a region, and can have 255 hotspot regions set in the image.

    Gremmy..
    Last edited by GremlinSA; January 16th, 2009 at 01:33 AM.
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  10. #10
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Hotspots in .Net

    OK. That makes sense. I've used a Mask image before, but it was two-color only
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  11. #11
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    Re: Hotspots in .Net

    Quote Originally Posted by GremlinSA View Post
    I made it even easier than that ...

    Because Pic2 is a background mask,.....
    That is a clean and usually better approach....but, the original post:
    based on a picture
    Technically eliminated any approach where 2 images (one for display one for mask) was used.

    Once one "plays with" the two image approach and is comfortable in understanding its operation, it should not be difficult to make the jump to slight restrictions in the image colors. e.g. only even shades so that the least significant bit is not used to convey color, but rather conveys (part of) the mask.


    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  12. #12
    Join Date
    Jun 2004
    Location
    NH
    Posts
    674

    Re: Hotspots in .Net

    TheCPUWizard,
    Man, you just disagree with everything.
    Technically, the original post didn't say
    "based on one picture"
    That was your own mental restriction.

  13. #13
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Hotspots in .Net

    Once one "plays with" the two image approach and is comfortable in understanding its operation, it should not be difficult to make the jump to slight restrictions in the image colors. e.g. only even shades so that the least significant bit is not used to convey color, but rather conveys (part of) the mask.
    Have any code? I was trying to figure out how you'd go about setting LSB of the original image...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  14. #14
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    Re: Hotspots in .Net

    Quote Originally Posted by dglienna View Post
    Have any code? I was trying to figure out how you'd go about setting LSB of the original image...
    I answered that publically back in Reply #8, (and also sent you detailed information via PM....

    Step #1: AND each pixel with 0xFFFEFEFE
    Step #2: Convert Hot Spot ID 1-7 into 0X000001, 0X0000100, 0X0000101, 0X010000, 0x010001, 0x010100, 0x010101
    Step #3: Or Value with color.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  15. #15
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    Re: Hotspots in .Net

    For those who can not find the original material on stegography and its utilization for hotspots, or have problems with the c++ implementation in the article, here is a (non-optimized) VB.NET

    Code:
    Public Shared Sub Encode(ByVal src As Bitmap, ByVal mask As Bitmap, ByVal key As List(Of Color))
        Dim x As Integer
        For x = 0 To src.Width - 1
            Dim y As Integer
            For y = 0 To src.Height - 1
                Dim rgb As Integer = (src.GetPixel(x, y).ToArgb And -65794)
                Dim m As Integer = key.IndexOf(mask.GetPixel(x, y))
                rgb = (rgb Or HotSpot.t(m))
                src.SetPixel(x, y, Color.FromArgb(rgb))
            Next y
        Next x
    End Sub
    
     Public Shared Function HotIndex(ByVal src As Bitmap, ByVal x As Integer, ByVal y As Integer) As Integer
        Dim m As Integer = (src.GetPixel(x, y).ToArgb And &H10101)
        Dim i As Integer
        For i = 0 To 8 - 1
            If (HotSpot.t(i) = m) Then
                Return i
            End If
        Next i
        Return 0
    End Function
    
     Shared Sub New()
        HotSpot.t = New Integer() { 0, 1, &H100, &H101, &H10000, &H10001, &H10100, &H10101 }
    End Sub
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center