Results 1 to 3 of 3

Thread: How do I switch blue and red pixels in color, not an image

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2021
    Posts
    79

    How do I switch blue and red pixels in color, not an image

    Using Visual Studio 2019, I want to make PictureBox1.BackColor Swap blue and red colors, I tried this
    Code:
       Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
            PictureBox1.BackColor.B = PictureBox1.BackColor.R
            PictureBox1.BackColor.G = PictureBox1.BackColor.G
            PictureBox1.BackColor.R = PictureBox1.BackColor.B
            PictureBox1.BackColor.A = PictureBox1.BackColor.A
        End Sub
    and this
    Code:
            Dim blue As Byte = PictureBox1.BackColor.R
            Dim green As Byte = PictureBox1.BackColor.G
            Dim red As Byte = PictureBox1.BackColor.B
            Dim alpha As Byte = PictureBox1.BackColor.A
            PictureBox1.BackColor.ToArgb(blue, green, red, alpha)
    (Convert RGBA to BGRA or ARGB to ABGR)

    How do I reorder ARGB? (Yellow may look Cyan, for example.)
    I already got a negative effect. (Yellow may look Blue, for example.)

    I can't find a working way of making RGB become BGR. I found some ways of doing it with images, but I wanted to do it with the color in the background of the tool.
    Last edited by Winston17; May 9th, 2022 at 07:30 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: How do I switch blue and red pixels in color, not an image

    You need to get the existing Color, create a new Color from that and then replace the existing Color with the new:
    vb.net Code:
    1. Dim currentColor = PictureBox1.BackColor
    2. Dim newColor = Color.FromArgb(currentColor.A,
    3.                               currentColor.B,
    4.                               currentColor.G,
    5.                               currentColor.R)
    6.  
    7. PictureBox1.BackColor = newColor

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,600

    Re: How do I switch blue and red pixels in color, not an image

    You could also do it like this:-
    Code:
            Dim funcSwap = Function(c) Color.FromArgb(c.ToArgb And &HFF00FF00 Or c.R Or CInt(c.B) << 16)
    
            PictureBox1.BackColor = funcSwap(PictureBox1.BackColor)
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

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