marcuslee
Jan 10, 2008
Submit Articles Here for Liberty BASIC Programmer's Encyclopedia Creating an Image Map
By: Mark Lee
January 10, 2008Download a zip file containing an example
An image map is a picture with clickable regions. Image maps are typically found on WebPages as navigational tools, allowing users to click on pictures or sections of a picture to go to other pages.
How To
Create an image with solid colored regions. Bitmaps (Bmps) take up a lot of space, so using high quality Jpegs might be
The next step is to convert the RGB color codes of the solid color regions to single numbers, which are used by windows to read pixel values. I used the following code to do this.
[begin]
input red
input green
input blue
print RGB(red, green, blue)
input again$
if again$ = "y" then [begin]
end
Function RGB(red, green, blue)
RGB= red + (green * 256) + (blue * 65536)
End Function
Now, write a program to scan your image, indexing the color of each pixel in the clickable regions. Store this information in a Random Access File database. Colors that are not
'index the pixels
PixelNumber = 1
for yVar = 0 to 629 'Cycle through the height of the image to be scanned
for xVar = 0 to 319 'Cycle through the width of the image to be scanned
pixelLong = pixelLong(xVar, yVar)
Select Case pixelLong
Case 8421504 ' Face
Part$ = "1"
PUT #Body, PixelNumber
PixelNumber = PixelNumber + 1
Case 16711553 ' Neck
Part$ = "2"
PUT #Body, PixelNumber
PixelNumber = PixelNumber + 1
Case 16512 ' Shoulders
Part$ = "3"
PUT #Body, PixelNumber
PixelNumber = PixelNumber + 1
Case 16646144 'Chest
Part$ = "4"
PUT #Body, PixelNumber
PixelNumber = PixelNumber + 1
Case 254 ' Arms
Part$ = "5"
PUT #Body, PixelNumber
PixelNumber = PixelNumber + 1
Case 131071 ' Hands
Part$ = "6"
PUT #Body, PixelNumber
PixelNumber = PixelNumber + 1
Case 16711807 ' Stomach
Part$ = "7"
PUT #Body, PixelNumber
PixelNumber = PixelNumber + 1
Case 16744448 ' Hips
Part$ = "8"
PUT #Body, PixelNumber
PixelNumber = PixelNumber + 1
Case 98304 ' Legs
Part$ = "9"
PUT #Body, PixelNumber
PixelNumber = PixelNumber + 1
Case 8388863 ' Feet
Part$ = "10"
PUT #Body, PixelNumber
PixelNumber = PixelNumber + 1
Case Else 'Non Body Part
Part$ = "0"
PUT #Body, PixelNumber
PixelNumber = PixelNumber + 1
End Select
next xVar
next yVar
Such a program may run for several minutes to index large pictures. It took my computer about 8 minutes to index a little more than 200,000 pixels. (That’s a 320 x 630 size image.)
The use of a few API/DLL calls, including the GetPixel function, will be required.
Function pixelLong(xVar, yVar)
hGBox = hWnd(#t.box)
hDC = hDC(hGBox)
Open "gdi32"for DLL as #gdi
CallDLL #gdi, "GetPixel",_
hDC as Ulong,_
xVar as Long,_
yVar as Long,_
pixelLong as Long
Close #gdi
CallDLL#user32,"ReleaseDC", _
hGBox as Ulong, _
hDC as Ulong, _
result as Long
End Function
Function hDC(hGBox)
Open "user32" for dll as #user
CallDLL #user, "GetDC",_
hGBox as Ulong,_
hDC as Ulong
Close #user
End Function
Each clickable region can have a separate picture associated with it. The new picture may replace the old picture when the mouse moves over the region or when a mouse button is either pressed or released. For that matter, a different picture could be triggered with each of the mentioned events. Options at this point are only hindered by your
The
I would like to thank Alyce for the use of
LIST ARTICLES HERE
- Scientific precision - by Grahame King - ADDED TO NUMBERS AND MATH -
Alyce Aug 24, 2006 - copying,moving,deleting and renaming files - by Alex Barfoot - added to Using Files, Windows API -
Alyce Aug 28, 2006 - Listview, trapping double click - by Eldron Gill - Added to Windows API -
JanetTerra , October 10, 2006 - CryptographyWithLB102 - by Cryptoman - Added to Strings and Text -
JanetTerra Oct 25, 2006 - A True API Popup Menu - By Duncan B - added to Windows API -
Alyce Mar 22, 2007 - Calculating the Value of PI - By Frank West added to Numbers and Math -
Alyce May 30, 2007 - Running a LB program from the System Tray - By Duncan B. (added to Advanced Tutorials by -
Alyce ) - Programming Using TOE Charts - By Noble D. Bell (added to General tutorials by -
Alyce ) - Sprite Boundary Detection Tip - By Ben Jimenez - Added to Graphics and Games > Sprite Games -
JanetTerra - Managing Multiple Windows - By Harmon V.
- Byte Mode Programming - Added to General Tutorial -
Alyce - Indexed Random Access in Native LB -
Alincon2001 - added to Uncategorized Contributions - Creating and Image Map - by Mark Lee