Results 1 to 3 of 3

Thread: Gray pictures!

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 1999
    Location
    Brazil
    Posts
    144

    Post

    How do I gray pictures! I use small pictureboxes 16x16 bitmaps in may app, and I wish gray them like a graphic button disabled or like IE menus!

    Some suggestions!
    Jefferson

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Most Apps will have a Pre-Drawn Greyed Equivelant of each Menu/Toolbar Item, but you can easily convert a Picture to Grey Scale by Calculating the Grey Value of Each Pixel, ie.
    Code:
    Private Sub Command1_Click()
        Dim iX As Integer
        Dim iY As Integer
        Dim iXPixel As Integer
        Dim iYPixel As Integer
        
        With Picture1
            .ScaleMode = vbPixels
            iX = ScaleX(.Picture.Width, vbHimetric, vbPixels)
            iY = ScaleY(.Picture.Height, vbHimetric, vbPixels)
            For iYPixel = 0 To iY
                For iXPixel = 0 To iX
                    'Convert each Pixel to its Grey Equivelant.
                    Picture1.PSet (iXPixel, iYPixel), GetGreyColor(.Point(iXPixel, iYPixel))
                Next
            Next
        End With
    End Sub
    
    Public Function GetGreyColor(ByVal lRGB As Long) As Long
        Dim iRed As Integer
        Dim iGreen As Integer
        Dim iBlue As Integer
        Dim lGrey As Long
        
        'Extract the RGB Components
        iRed = lRGB And vbRed
        iGreen = (lRGB And vbGreen) / (2 ^ 8)
        iBlue = (lRGB And vbBlue) / (2 ^ 16)
        'Set the Grey Color to the Mean Value of the Components
        lGrey = (iRed + iGreen + iBlue) / 3
        GetGreyColor = RGB(lGrey, lGrey, lGrey)
    End Function

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


  3. #3

    Thread Starter
    Registered User
    Join Date
    Apr 1999
    Location
    Brazil
    Posts
    144

    Post

    Thanks Aaron!
    Jefferson

Posting Permissions

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



Click Here to Expand Forum to Full Width