Image Masks...

Everything else that doesn't fall into one of the other PB categories.
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Image Masks...

Post by localmotion34 »

Im playing around with the toolbar pro LIB, and im trying to figure out how to create a "mask" from a strip in a bitmap. the bitmap is made up of icons pasted into photoshop, but i have no idea of how to get the mask like in the examples of the toolbar pro lib. any ideas?

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

All I've done in the past is make a copy of the image strip, load it into MS Paint and fill the background white. With the icons themselves, I just replace all regions coloured white, with black and leave the rest. It seems to work okay.

If you haven't come across the following, it comes well recommended:

http://www.snapfiles.com/get/toolbarpaint.html
I may look like a mule, but I'm not a complete ass.
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

huh? that still leaves me with no clue as to HOW you did it?

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Readup on how to use the selection tool and the magic wand tool in photoshop. You just need to select all the areas that you don't want to appear in the buttons and turn them to white. All the areas you do want to appear in buttons turn to black. easy.

1. select all the backgrounds using select tool or magic wand
2. turn the selection to white
3. invert the selection (menu command)
4. turn to black.
5. Save as 'mask.bmp'.
--Kale

Image
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I just hacked up the following which will create a basic mask from a given bitmap.

Code: Select all

;This small program takes an image in .bmp format and generates a correspomding mask
;suitable for Danilo's TOOLBAR pro etc.
;The mask is saved with 'Mask.bmp' appended to the name.

;By srod.
;Purebasic 4.

Enumeration ;images
  #bmap
EndEnumeration

Define pt.POINT, file$, hBmap, hMaskBmp, bmapdc, maskdc, transcolour

pt\x=0 : pt\y=0 ;This means that the colour of the point(0, 0) in the selected image will
;be taken to be the transparent background etc. This will appear as white in the mask.
;Change as appropriate.
;Alternatively, change the value of the variable 'transcolour' below to an appropriate
;colour value.

;Open a file requester in order to select an image.
  file$=OpenFileRequester("Select bitmap image...", GetCurrentDirectory(), "Bitmap | *.bmp",0)
  If FileSize(file$)>0
    hBmap=LoadImage(#bmap,file$)
    bmapdc=StartDrawing(ImageOutput(#bmap))
;Set background colour (see above comment).
      transcolour=Point(pt\x,pt\y)
;Now create the mask which ends up back in our original image.
      maskDC = CreateCompatibleDC_(bmapdc) 
      hMaskBmp = CreateBitmap_(ImageWidth(#bmap), ImageHeight(#bmap), 1, 1, 0) 
      SelectObject_(maskdc, hMaskBmp) 
      SetBkColor_(bmapdc, transcolour) 
      BitBlt_(maskdc, 0, 0, ImageWidth(#bmap), ImageHeight(#bmap), bmapdc, 0, 0, #SRCCOPY)
      SetBkColor_(bmapdc, #White) 
      BitBlt_(bmapdc, 0, 0, ImageWidth(#bmap), ImageHeight(#bmap), maskdc, 0, 0, #SRCCOPY)
    StopDrawing()
;Tidy up.
    DeleteDC_(maskDC)
    DeleteObject_(hMaskBmp)
;Now save the mask image.
    file$=ReplaceString(file$,".bmp","Mask.bmp") 
    SaveImage(#bmap,file$)
  EndIf
It's not very sophisticated and there's not much error checking, but it seems to work.
I may look like a mule, but I'm not a complete ass.
Post Reply