[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 flashercs 于 2019-3-28 06:55 编辑

用powershell找色也行吧.设 RGB中至少两个原色不同的点为彩色点,当图片底部的1/3区域中的彩色点数量达到10%时 ,该图片被认为是彩图.
下面代码并未真正重命名图片,只是找出符合条件的图片; 保存为 "彩图".bat,设置变量PicturePath为要处理的图片或所在目录的路径列表,以空格分隔开
  1. @echo off
  2. set PicturePath="E:\test\dir1" "E:\test\dir2" "E:\test\dir3" "E:\test\dir4\00053.jpg"
  3. for /f "tokens=1 delims=:" %%A in ('findstr /n "#######*" %0') do more +%%A %0 >"%~dpn0.ps1"
  4. powershell.exe -ExecutionPolicy Bypass -File "%~dpn0.ps1" %PicturePath%
  5. pause
  6. exit /b
  7. ################################################################
  8. [boolean]$isRecursive = $false # 是否处理子目录
  9. function testColor {
  10.   param (
  11.     [string]$filepath
  12.   )
  13.   $bitmap = New-Object -TypeName System.Drawing.Bitmap -ArgumentList $filepath
  14.   # $bitmap = [System.Drawing.Bitmap]::new($filepath)
  15.   $height = $bitmap.Height
  16.   $width = $bitmap.Width
  17.   # 彩色点数目下限设置为图片底部1/3的点数的10%
  18.   $minPoints = [System.Math]::Floor(0.1 * $width * $height / 3)
  19.   $count = 0
  20.   $flag = $false
  21.   :outer
  22.   for ($y = [System.Math]::Ceiling($height * 2 / 3) - 1; $y -lt $height; $y++) {
  23.     for ($x = 0; $x -lt $width; $x++) {
  24.       $color = $bitmap.GetPixel($x, $y)
  25.       if (!($color.R -eq $color.G -and $color.R -eq $color.B)) {
  26.         if (++$count -ge $minPoints) {
  27.           $flag = $true
  28.           break outer
  29.         }
  30.       }
  31.     }
  32.   }
  33.   # Write-Host "`$y = $y;`$x = $x" -ForegroundColor Magenta
  34.   $bitmap.Dispose()
  35.   return $flag
  36. }
  37. function genFile {
  38.   param (
  39.     [string]$filepath
  40.   )
  41.   Write-Host $filepath -ForegroundColor Green
  42.   if (testColor $filepath) {
  43.     Rename-Item -LiteralPath $filepath -NewName ([System.IO.Path]::GetFileNameWithoutExtension($filepath) + 'C' + [System.IO.Path]::GetExtension($filepath)) -WhatIf
  44.   }
  45. }
  46. function genFolder {
  47.   param (
  48.     [string]$folderPath,
  49.     [switch]$recurse
  50.   )
  51.   if ($recurse) {
  52.     Get-ChildItem -LiteralPath $folderPath -Filter '*.jpg' -File -Recurse|ForEach-Object {genFile $_.FullName}
  53.   }
  54.   else {
  55.     Get-ChildItem -LiteralPath $folderPath -Filter '*.jpg' -File|ForEach-Object {genFile $_.FullName}
  56.   }
  57. }
  58. Add-Type -AssemblyName System.Drawing|Out-Null
  59. Write-Host "`$args.Count=$($args.Count)"
  60. foreach ($item in $args) {
  61.   if ((Get-Item -LiteralPath $item).Attributes -band [System.IO.FileAttributes]::Directory) {
  62.     genFolder $item $isRecursive
  63.   }
  64.   else {
  65.     genFile $item
  66.   }
  67. }
复制代码
4

评分人数

微信:flashercs
QQ:49908356

TOP

返回列表