Skip to content

Instantly share code, notes, and snippets.

@honex
Created March 12, 2015 07:40
Show Gist options
  • Save honex/a019a812f7263eb0404b to your computer and use it in GitHub Desktop.
Save honex/a019a812f7263eb0404b to your computer and use it in GitHub Desktop.
画像ファイルの黒を白に
#画像ファイルの黒を白に変換する関数
function convcolor-b2w
{
begin { Write-Host "黒→白に置き換え"
[Void][System.Reflection.Assembly]::LoadWithPartialName( "System.Drawing" )
$activepath = Get-Location
$colormap = New-Object System.Drawing.Imaging.Colormap
$colormap.OldColor = "Black"
$colormap.NewColor = "White"
$ia = New-Object System.Drawing.Imaging.ImageAttributes
$ia.SetRemapTable( $colormap )
}
process {
trap {
"対象ファイルをパイプラインで入力してください"
"異常終了!"
break
}
Write-Host "$_"
$img = [System.Drawing.Image]::FromFile( "$_" )
$g = [System.Drawing.Graphics]::FromImage( $img )
$rect = New-Object System.Drawing.Rectangle( 0, 0, $img.Width, $img.Height )
$g.DrawImage( $img, $rect, 0, 0, $img.Width, $img.Height, "Pixel", $ia)
$outfile = "$activepath" + "\trs_" + $_.basename + ".tif"
Write-Host $outfile
$img.save( "$outfile" , "tiff" )
$g.dispose()
$img.dispose()
}
end { Write-Host "変換完了" }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment