Copy a picture and remove color or make it darker

Rather than make two sets of button icons I’d like to create two sets in code from a single Image Set, one normal and one pressed. Is there a way to create a copy of a picture but make it darker or remove the color of the image to create a “button pressed” version? (for Mac + Win).

Thanks in advance,



[code]Protected Function MakeDarker(original as Picture, amount as double) as Picture
Dim n As Integer=original.ImageCount
If n=0 Then
Return MakeDarkerInner(original, amount)
Dim pp() As Picture
for i as integer=0 to n
pp.Append MakeDarkerInner(original.IndexedImage(i), amount)
Return new Picture(original.Width, original.Height, pp)
End If
End Function

Private Function MakeDarkerInner(OriginalPicture as Picture, theAmount as Double) as Picture
'change the value (lighter or darker) for the Original Picture

Dim OriginalHeight As Integer = OriginalPicture.height
Dim OriginalWidth As Integer = OriginalPicture.width

Dim OriginalRGBS As RGBSurface = OriginalPicture.RGBSurface

//If you want, you can use the new constructor (without mask object)
dim ResultPicture as new Picture(OriginalPicture.Width, OriginalPicture.Height, 32)
'Dim ResultPicture As New Picture(OriginalPicture.Width, OriginalPicture.Height)
dim ResultRGBS as RGBSurface = ResultPicture.RGBSurface

for currentX as Integer = 0 to OriginalWidth
for currentY as Integer = 0 to OriginalHeight
dim theColor as Color = OriginalRGBS.Pixel(currentX, currentY)
ResultRGBS.Pixel(currentX, CurrentY) = HSV(theColor.Hue, theColor.Saturation, theColor.Value * theAmount)
If OriginalPicture.Mask=Nil Then
//if you use the ,32 constructor set the mask
//otherwise apply it
ResultPicture.ApplyMask OriginalPicture.CopyMask
//if you use the ,32 constructor set the mask ResultPicture.Mask = OriginalPicture.mask
//otherwise apply it
ResultPicture.ApplyMask OriginalPicture.Mask
End If
Return ResultPicture
End Function[/code]

This is for HiDPI enabled. Made with some help here on the forum.

Many thanks Beatrix and all those that helped. Exactly what I needed, and even with the handling for Image Set pictures which I’ve been working on.