Results 1 to 4 of 4

Thread: change color of custom shape(bitmap)in runtime

  1. #1

    Thread Starter
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    Is it possible to change the color of a custom shape (bitmap; for example a shape consiting of several lines and circles)during runtime??

  2. #2
    Fanatic Member kinjalgp's Avatar
    Join Date
    Apr 2000
    Location
    India
    Posts
    535

    Talking

    Yes it is possible.

    Make an array of your custom shapes like Shape(1), Shape(2).....etc
    and then do this

    Private sub SomeObject_SomeEvent()
    for i = 0 to Shape.Count - 1
    Shape(i).Bordercolor = RGB(255,0,0)
    Shape(i).Fillcolor = RGB(0,0,255)
    Next
    End Sub

    Hope this is what you had asked for.
    Kinjal

  3. #3
    Fanatic Member kinjalgp's Avatar
    Join Date
    Apr 2000
    Location
    India
    Posts
    535
    And if you want to change the color of a bitmap then I think you have to put another color bitmap in a separate invisible picture box(e.xx Picture2, Autosize = True) on the form and then do this

    Private Sub SomeObject_SomeEvent()
    Picture1.Picture = Picture2.Image
    End Sub

    Kinjal

  4. #4
    Guest
    I do not quite understand your question. Do you want to change the Colour of a Bitmap? If so, you can use a Brute-Force method.

    This example checks each Pixel in your Picture. If it is a Red Pixel, then it will be converted to Blue.

    Code:
    Private Sub Command1_Click()
    
        Dim iLength As Integer
        Dim iWidth As Integer
        
        'Set the variables to the Height and Width of the Picture
        iLength = Picture1.Height
        iWidth = Picture1.Width
        
        'Loop through each Pixel of the Picture
        For y = 0 To iLength
            For x = 0 To iWidth
                'DoEvents makes sure the OS doesn't freeze
                DoEvents
                'Get the Pixel
                Retval = GetPixel(Picture1.hdc, x, y)
                'If it's Red then convert it to Blue
                If Retval = vbRed Then SetPixel Picture1.hdc, x, y, vbBlue
            Next x
        Next y
    
    End Sub

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