使用PowerShell获取图像的调色板 [英] Get Color Palette of Image using PowerShell
本文介绍了使用PowerShell获取图像的调色板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取图像的调色板
。我尝试了各种方法,现在在 PowerShell
中使用以下代码,但无法获得正确的结果:
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
}
结果带给我更多超过一千个 RGB
代码:
The result take me more than thousand RGB
codes:
推荐答案
我认为,调色板是指图像中出现的不同色带。
I assume that by "color palette" you mean the swathe of distinct colours that appear in the image.
仅选择集合的不同子集的一种简单(且非常快速)的方法是使用哈希表。
A simple (and quite fast) way to select only a distinct subset of a collection is to use a hashtable.
$filename = 'C:\Users\schoo\Desktop\bb.jpg'
$BitMap = [System.Drawing.Bitmap]::FromFile((Resolve-Path $filename).ProviderPath)
# A hashtable to keep track of the colors we've encountered
$table = @{}
foreach($h in 1..$BitMap.Height){
foreach($w in 1..$BitMap.Width) {
# Assign a value to the current Color key
$table[$BitMap.GetPixel($w - 1,$h - 1)] = $true
}
}
# The hashtable keys is out palette
$palette = $table.Keys
这篇关于使用PowerShell获取图像的调色板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文