Created
March 12, 2015 07:40
-
-
Save honex/a019a812f7263eb0404b to your computer and use it in GitHub Desktop.
画像ファイルの黒を白に
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #画像ファイルの黒を白に変換する関数 | |
| 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