Get Color Palette of Image Using PowerShell

Welcome Forums General PowerShell Q&A Get Color Palette of Image Using PowerShell

This topic contains 3 replies, has 3 voices, and was last updated by

1 year, 4 months ago.

  • Author
  • #81509

    Points: 1
    Rank: Member

    I am trying to get the `Color Palette` of an image. I tried various methods, and now I use the following code in `PowerShell`, but I could not get the correct result:

    $filename = "C:\Users\schoo\Desktop\bb.jpg"
        $BitMap = [System.Drawing.Bitmap]::FromFile((Get-Item $filename).fullname) 
        Foreach($y in (1..($BitMap.Height-1))){ 
          Foreach($x in (1..($BitMap.Width-1))){ 
                 $Pixel = $BitMap.GetPixel($X,$Y)         
                 $BackGround = $Pixel.Name
        $R = $Pixel | select -ExpandProperty R
        $G = $Pixel | select -ExpandProperty G
        $B = $Pixel | select -ExpandProperty B
        $A = $Pixel | select -ExpandProperty A
        $allClr = "$R" + "." + "$G" + "." + "$B" + "." + "$A"

    The result take me more than thousand `RGBA` codes!
    I want to get some average RGB codes, please see this result:

  • #81530

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Honestly, I'm not sure this is a “PowerShell question” per se. I have zero experience manipulating images, for example. I mention it only because you're basically doing .NET programming – and you might get a better answer on a dev-focused site like This site ends up just being more about administrative automation than image manipulation... sorry :).

    • #81547

      Points: 1
      Rank: Member

      I appreciate you to answer my question, and your sound. in fact i got some fixable code to answering this Q, but now I getting some issue, it maybe you can fixed.
      Now I have some member, can I damage or join those together? for example:

      PS D:\> $table.Keys | select R, G, B
        R   G   B
        -   -   -
      255 240   0
        0 255   0
      255 138   0
      255   0 234

      I want to join R,G,B as like: "255.240.0" extra

  • #81550

    Points: 727
    Helping Hand
    Rank: Major Contributor

    You really should take a little time and start to learn the basics of Powershell

    $table.Keys | ForEach-Object {($_.R,$_.G,$_.B ) -join '.'}

The topic ‘Get Color Palette of Image Using PowerShell’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort