Jump to content

Image Mapping


Recommended Posts

Hi,

I was wondering, is there a way to map out an image in AutoIT similar to how you would map an image out in HTML? Essentially its only square or rectangular mapping areas so there isnt a need for any weird polygonal shapes/coordinates.

What I am planning on doing is creating a program that manages our current internal network. What is going to happen is that I am going to put our cubicle layouts in a picture and map each one out. When you hover over each cube, it will give you the name of the person sitting there and if you click on it, it will expand a new window that will go into more detail and have a button for launching a VNC connection to their computer.

At some point, I was also planning on having the floorplan show in colors if a computer is on or off by using a ping or something of the sort (ex. if the ping fails, then that cubicle area would go red)

One thing at a time though :D

Image Mapping

Thanks!

Link to comment
Share on other sites

I would use an _IECreateEmbedded :D

THen On When you Click on a Imagemap-Link, set a hidden Form filed to a specified value.

In AutoiT-Script, Read the Filed in a while-Loop and do the Actions depending on this value :D

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

I would use an _IECreateEmbedded :D

THen On When you Click on a Imagemap-Link, set a hidden Form filed to a specified value.

In AutoiT-Script, Read the Filed in a while-Loop and do the Actions depending on this value :D

I'd rather not do anything with the web-browser and would like to keep it just within AutoIT and not calling any other programs. Plus, HTML is yucky lol. I just would rather map it out somehow in AutoIT rather than in HTML and then calling the file.

Link to comment
Share on other sites

You can either use the Control from Here directly: http://www.freevbcode.com/ShowCode.asp?ID=2988

or you use it as base and write it native in AutoIT :D

This is an example with the oxc (needs Paintx.dll, too)

#include <GUIConstants.au3>
Global $RegisteredTheOCXImageMapVB = False
Func _RegisterImageMap()
    ConsoleWrite("->> Register ImageMap"&@CRLF)
    RunWait("regsvr32 ImageMapVB.ocx /s",@ScriptDir,@SW_HIDE)
EndFunc

Func _CreateImageMapObj()
    Local $map = ObjCreate("ImageMapVB.VBImageMap")
    If @error Then 
        $RegisteredTheOCXImageMapVB = True
        _RegisterImageMap()
        $map = ObjCreate("ImageMapVB.VBImageMap")
        If @error Then Exit MsgBox(0, '', "Needs ImageMapVB from http://www.freevbcode.com/ShowCode.asp?ID=2988")
    EndIf
    Return $map
EndFunc
#region - GUI Create
$map = _CreateImageMapObj()
GUICreate('test')
$obj = GUICtrlCreateObj($map,10,10,250,136)
$map.ControlMode = 1 ;Mode 1: Runtime, Mode 2-4 different Design-Modes.
$map.BackColor = 0xFFFFFF
$map.HTMLText='<map id="Demo1" name="MerrionComputing_ImageMap"><area id="Yellow Square" shape="rectangle" coords="9,9,39,39"><area id="Red Square" shape="rectangle" coords="51,9,79,39"><area id="Green Square" shape="rectangle" coords="96,9,122,39"><area id="Dark Blue Square" shape="rectangle" coords="140,9,169,39"><area id="Pink Square" shape="rectangle" coords="186,9,215,39"><area id="Red Circle" shape="circle" coords="23,64,15,15"><area id="Blue Circle" shape="circle" coords="67,64,15,15"><area id="Yellow Circle" shape="circle" coords="108,64,15,15"><area id="Green Circle" shape="circle" coords="155,64,15,15"><area id="Beige Circle" shape="circle" coords="201,64,15,15"><area id="Green Triangle" shape="polygon" coords="10,93,35,93,23,117"></map>'
GUISetState()
#endregion
_ImageMapSetImage($map,"TestOne.bmp")
ObjEvent($map,"VBImageMap1_") ; Set the Events
#region - GUI SelectLoop
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            
            Exit

    EndSelect
WEnd
#endregion
Func OnAutoItExit()
    If $RegisteredTheOCXImageMapVB Then
        RunWait("regsvr32 ImageMapVB.ocx /s /u",@ScriptDir,@SW_HIDE)
        ConsoleWrite("->> Unregister ImageMap"&@CRLF)
    EndIf
EndFunc

Func VBImageMap1_MapItemClicked($Item); ImageMapVB.ImageMapItem

    MsgBox(0,"MapItemClicked()", "You clicked on " & $Item.ImageMapItemId)

EndFunc

Func VBImageMap1_MapItemMouseOver($Item); As ImageMapVB.ImageMapItem)

If Not IsObj($Item) Then
    ToolTip("Over nothing")
Else
    ToolTip("Over " & $Item.ImageMapItemId)
EndIf

EndFunc

Func _ImageMapSetImage(ByRef $map,$value)
    If Not FileExists($value) Then Return SetError(2,0,0)
    Local $TPictureLoad = ObjCreate("PaintX.PictureDecoder")
    Local $loaded = 0
    If @error Then
        Local $loaded = 1
        ConsoleWrite("->> Register ImageLodaer (PaintX)"&@CRLF)
        RunWait("regsvr32 PaintX.dll /s",@ScriptDir,@SW_HIDE)
        $TPictureLoad = ObjCreate("PaintX.PictureDecoder")
        If @error Then Exit MsgBox(0, '', "Needs PaintX from http://www.paintlib.de/paintlib/download.html")
    EndIf
    $map.Picture =  $TPictureLoad.LoadPicture($value)
    $TPictureLoad = 0
    If $loaded Then
        ConsoleWrite("->> UnRegister ImageLodaer (PaintX)"&@CRLF)
        RunWait("regsvr32 PaintX.dll /s /u",@ScriptDir,@SW_HIDE)
    EndIf
EndFunc

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

You can either use the Control from Here directly: http://www.freevbcode.com/ShowCode.asp?ID=2988

or you use it as base and write it native in AutoIT :D

This is an example with the oxc (needs Paintx.dll, too)

#include <GUIConstants.au3>
Global $RegisteredTheOCXImageMapVB = False
Func _RegisterImageMap()
    ConsoleWrite("->> Register ImageMap"&@CRLF)
    RunWait("regsvr32 ImageMapVB.ocx /s",@ScriptDir,@SW_HIDE)
EndFunc

Func _CreateImageMapObj()
    Local $map = ObjCreate("ImageMapVB.VBImageMap")
    If @error Then 
        $RegisteredTheOCXImageMapVB = True
        _RegisterImageMap()
        $map = ObjCreate("ImageMapVB.VBImageMap")
        If @error Then Exit MsgBox(0, '', "Needs ImageMapVB from http://www.freevbcode.com/ShowCode.asp?ID=2988")
    EndIf
    Return $map
EndFunc
#region - GUI Create
$map = _CreateImageMapObj()
GUICreate('test')
$obj = GUICtrlCreateObj($map,10,10,250,136)
$map.ControlMode = 1 ;Mode 1: Runtime, Mode 2-4 different Design-Modes.
$map.BackColor = 0xFFFFFF
$map.HTMLText='<map id="Demo1" name="MerrionComputing_ImageMap"><area id="Yellow Square" shape="rectangle" coords="9,9,39,39"><area id="Red Square" shape="rectangle" coords="51,9,79,39"><area id="Green Square" shape="rectangle" coords="96,9,122,39"><area id="Dark Blue Square" shape="rectangle" coords="140,9,169,39"><area id="Pink Square" shape="rectangle" coords="186,9,215,39"><area id="Red Circle" shape="circle" coords="23,64,15,15"><area id="Blue Circle" shape="circle" coords="67,64,15,15"><area id="Yellow Circle" shape="circle" coords="108,64,15,15"><area id="Green Circle" shape="circle" coords="155,64,15,15"><area id="Beige Circle" shape="circle" coords="201,64,15,15"><area id="Green Triangle" shape="polygon" coords="10,93,35,93,23,117"></map>'
GUISetState()
#endregion
_ImageMapSetImage($map,"TestOne.bmp")
ObjEvent($map,"VBImageMap1_") ; Set the Events
#region - GUI SelectLoop
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            
            Exit

    EndSelect
WEnd
#endregion
Func OnAutoItExit()
    If $RegisteredTheOCXImageMapVB Then
        RunWait("regsvr32 ImageMapVB.ocx /s /u",@ScriptDir,@SW_HIDE)
        ConsoleWrite("->> Unregister ImageMap"&@CRLF)
    EndIf
EndFunc

Func VBImageMap1_MapItemClicked($Item); ImageMapVB.ImageMapItem

    MsgBox(0,"MapItemClicked()", "You clicked on " & $Item.ImageMapItemId)

EndFunc

Func VBImageMap1_MapItemMouseOver($Item); As ImageMapVB.ImageMapItem)

If Not IsObj($Item) Then
    ToolTip("Over nothing")
Else
    ToolTip("Over " & $Item.ImageMapItemId)
EndIf

EndFunc

Func _ImageMapSetImage(ByRef $map,$value)
    If Not FileExists($value) Then Return SetError(2,0,0)
    Local $TPictureLoad = ObjCreate("PaintX.PictureDecoder")
    Local $loaded = 0
    If @error Then
        Local $loaded = 1
        ConsoleWrite("->> Register ImageLodaer (PaintX)"&@CRLF)
        RunWait("regsvr32 PaintX.dll /s",@ScriptDir,@SW_HIDE)
        $TPictureLoad = ObjCreate("PaintX.PictureDecoder")
        If @error Then Exit MsgBox(0, '', "Needs PaintX from http://www.paintlib.de/paintlib/download.html")
    EndIf
    $map.Picture =  $TPictureLoad.LoadPicture($value)
    $TPictureLoad = 0
    If $loaded Then
        ConsoleWrite("->> UnRegister ImageLodaer (PaintX)"&@CRLF)
        RunWait("regsvr32 PaintX.dll /s /u",@ScriptDir,@SW_HIDE)
    EndIf
EndFunc
Hmmm...I like how that looks. I plan on putting this program into an installer form so I might do the registration of the dll and ocx file in there. My problem right now with that code is that it will not register the ocx file. When I manually run the regsrv32 to see whats the deal, it will not register the file either and instead will give me an error as noted in the attached screenshot.

Looking through your code though, it looks as if it would be exactly what I would need to get this up and running.

Let me know if there are other missing DLL files or whatnot associated with that ocx file so that I can run your sample code and try it out.

(BTW, I have already downloaded the PaintX DLL as well as the sample VB ImageMap zip file which is where I got the ImageMap ocx file.)

post-34116-1208792027_thumb.jpg

Link to comment
Share on other sites

Very nice. I like how that works. A couple of things though that I did notice:

1- the tooltips seem to flicker while you move the mouse and even when the mouse lays dormant. Any suggestions?

2- Im guessing that the "GUICtrlCreateObj($map,10,10,250,136)" is basically just telling the program where it is to be using that image mapping control? Now are the coordinates that you put in for each object relative to within the coordinates of the window or are they relative to the coordinates of the picture?

Thanks for the great post BTW. I hope to get some pics finished up from my old CAD drawings soon.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...