Results 1 to 4 of 4

Thread: questions on rgb/argb

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    questions on rgb/argb

    Q1. is there a way to set an argb value to a Control?
    Code:
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.AllowTransparency = True
            Me.BackColor = Color.FromArgb(155, 255, 0, 0)
        End Sub
    i get error when setting BackColor "control does not support tarnsparent background colors"

    Q2. is there any difference between this 2:
    argb(255,0,0,127) "opacity is 1, blue is half" and
    argb(127,0,0,255) "opacity is half, blue is max"

    Q3. what if there are rounding off errors in the conversion to/from argb/rgb
    say argb(200,0,0,150) when converted to 255 opacity i get (255,0,0,117.5585938~)
    can i say that argb(255,0,0,118) is exactly equal to argb(200,0,0,150) or is argb(255,0,0,117) exactly equal to argb(200,0,0,150), or is there no way to exactly convert argb(200,0,0,150) to a value with alpha at 255?

    Q4. is it true that there is absolutely no relation between argb and rgb, because the actual rgb value of an argb depends on the color of the element behind it
    Last edited by pacerier; Dec 14th, 2009 at 10:01 AM.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: questions on rgb/argb

    1) The two are seriously different. If you just compare 0,0,127 to 0,0,255, you will see that both are blue, but of much different shade. Changing the alpha level should just alter how much of the background color bleeds through whichever shade you are setting. With that error, you might as well leave off the A value.

    2) The two are not EXACTLY equal. In fact, I would expect that you can see the difference, though it will not be strong. As for the overall question, I think you have to consider what your true objective is. If you need the color to return a certain value, then you might be better off just dropping the alpha channel for the conversion (act as if alpha was always just 255). If you need it to look a certain way, remember all those optical illusions where a colored stripe looks different when placed against a different colored background, and realize that perception is going to be faulty no matter what you do, so there may be no 'right' answer.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Re: questions on rgb/argb

    hmm alrite thanks for the tip anyways is argb even frequently used for?

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: questions on rgb/argb

    Quote Originally Posted by pacerier View Post
    hmm alrite thanks for the tip anyways is argb even frequently used for?
    Setting a transparent BackColor works to some extent for controls but not for forms (Form.AllowTransparency is just a swindle). For example, I made the transparent blue label shown below like this:
    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Label1.BackColor = Color.FromArgb(127, 0, 0, 255)
        End Sub
    ARGB colours are really useful when you are painting with Graphics (e.g. in a Paint event sub), because that supports transparency properly. You can get all kinds of nice effects with transparent pens, brushes and gradients.

    About your question 3. You could change the A value of a colour without changing the RGB settings like this:
    Code:
    Dim clr As Color = Color.Violet
    Dim transparentViolet As Color = Color.FromArgb(127, clr.R, clr.G, clr.B)
    bye, BB
    Attached Images Attached Images  

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