Author Posts

October 7, 2017 at 7:44 am

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"
    $allClr  
    }

The result take me more than thousand `RGBA` codes!
I want to get some average RGB codes, please see this result: http://bit.ly/2xo7cuB

October 7, 2017 at 9:28 pm

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 StackOverflow.com. This site ends up just being more about administrative automation than image manipulation... sorry :).

October 8, 2017 at 6:01 pm

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

October 9, 2017 at 12:12 am

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

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