Results 1 to 4 of 4

Thread: [VB6] Color Functions - Blending, etc

  1. #1

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    [VB6] Color Functions - Blending, etc

    To help someone else, I put together some color functions and thought I'd share it for anyone else to use/abuse. The class contains functions that can be pulled out (for the most part) individually and added to existing projects or it can be used as is. Use it more as a learning tool. Read the comments throughout the class.

    The gist of the attached class is manual color modifications: blending, color & lightness addition/subtraction, conversion between different color formats, premultipllication, gray scaling, and several more routines.

    I do not plan on appending new routines/functions to this class. However, there are dozens upon dozens of other color functions/matrices out on the web. Maybe start your own collection.

    Edited: Here's another function. I'll leave it to you to build an Array version of it if needed.
    Code:
    Public Function UnPremultiplyColor(ByVal Color As Long) As Long
    ' remove premultiplication and returns a color in RGBA format
    ' Note: Premultiplication is not 100% recoverable. The returned
    '   color compared to its original color is dependent upon the
    '   alpha level. The higher the alpha level the closer the
    '   returned color is to the original color.
    '   Any alpha value of zero will always return vbBlack as the color
        Dim R As Long, G As Long, B As Long, Alpha As Long
        If (Color And &HFF000000) <> 0& Then
             Alpha = Me.Alpha(Color)
             R = ((Color And &HFF&) * &HFF&) \ Alpha
             G = (((Color And &HFF00&) \ &H100&) * &HFF&) \ Alpha
             B = (((Color And &HFF0000) \ &H10000) * &HFF&) \ Alpha
             UnPremultiplyColor = (Color And &HFF000000) Or R Or G * &H100& Or B * &H10000
        End If
    End Function
    Attached Files Attached Files
    Last edited by LaVolpe; Aug 6th, 2010 at 01:12 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  2. #2
    Member
    Join Date
    Apr 2021
    Posts
    54

    Post Re: [VB6] Color Functions - Blending, etc

    Quote Originally Posted by LaVolpe View Post
    To help someone else, I put together some color functions and thought I'd share it for anyone else to use/abuse. The class contains functions that can be pulled out (for the most part) individually and added to existing projects or it can be used as is. Use it more as a learning tool. Read the comments throughout the class.

    The gist of the attached class is manual color modifications: blending, color & lightness addition/subtraction, conversion between different color formats, premultipllication, gray scaling, and several more routines.

    I do not plan on appending new routines/functions to this class. However, there are dozens upon dozens of other color functions/matrices out on the web. Maybe start your own collection.

    Edited: Here's another function. I'll leave it to you to build an Array version of it if needed.
    Code:
    Public Function UnPremultiplyColor(ByVal Color As Long) As Long
    ' remove premultiplication and returns a color in RGBA format
    ' Note: Premultiplication is not 100% recoverable. The returned
    '   color compared to its original color is dependent upon the
    '   alpha level. The higher the alpha level the closer the
    '   returned color is to the original color.
    '   Any alpha value of zero will always return vbBlack as the color
        Dim R As Long, G As Long, B As Long, Alpha As Long
        If (Color And &HFF000000) <> 0& Then
             Alpha = Me.Alpha(Color)
             R = ((Color And &HFF&) * &HFF&) \ Alpha
             G = (((Color And &HFF00&) \ &H100&) * &HFF&) \ Alpha
             B = (((Color And &HFF0000) \ &H10000) * &HFF&) \ Alpha
             UnPremultiplyColor = (Color And &HFF000000) Or R Or G * &H100& Or B * &H10000
        End If
    End Function

    Thank you very much for sharing your valuable code, excuse my ignorance but I would like to know how to send the parameters from a form.

    Thank you, teacher

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,910

    Re: [VB6] Color Functions - Blending, etc

    Quote Originally Posted by lizano diaz View Post
    ... send the parameters from a form.
    lizano,

    I feel that you mis-understand what LaVolpe is providing us in this CodeBank entry. Basically (in summary), he's providing us some tools for dealing with images that contain an alpha channel. Briefly, that's a channel (RGBA) that can be contained in an image for providing translucency (or opacity, which ever way you'd like to think about it) for each pixel within the image. In a straightforward VB6 way, this has virtually nothing to do with VB6 forms (even including images on forms, as they don't handle the alpha channel).

    Also, I'm not bad at VB6, but I'm clueless about what you're actual question is. And, I think you'd do well to try and expand on what you're asking, and also just start a new thread over in the main VB6 Q&A section.

    Also, LaVolpe said adios to us back in February, having started a new job that apparently had little to do with VB6. So, I'm not sure you should expect a reply from him.

    Good Luck,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  4. #4
    Member
    Join Date
    Apr 2021
    Posts
    54

    Re: [VB6] Color Functions - Blending, etc

    Quote Originally Posted by Elroy View Post
    lizano,

    I feel that you mis-understand what LaVolpe is providing us in this CodeBank entry. Basically (in summary), he's providing us some tools for dealing with images that contain an alpha channel. Briefly, that's a channel (RGBA) that can be contained in an image for providing translucency (or opacity, which ever way you'd like to think about it) for each pixel within the image. In a straightforward VB6 way, this has virtually nothing to do with VB6 forms (even including images on forms, as they don't handle the alpha channel).

    Also, I'm not bad at VB6, but I'm clueless about what you're actual question is. And, I think you'd do well to try and expand on what you're asking, and also just start a new thread over in the main VB6 Q&A section.

    Also, LaVolpe said adios to us back in February, having started a new job that apparently had little to do with VB6. So, I'm not sure you should expect a reply from him.

    Good Luck,
    Elroy

    Hello, what I wanted to say was an example of the use of the module, I don't have much skill.
    Thanks a lot

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