- #@&cls&powershell "type '%~f0'|out-string|iex"&pause&exit
- Add-Type -AssemblyName System.Drawing
- $cp = New-Object CodeDom.Compiler.CompilerParameters
- $cp.ReferencedAssemblies.Add([Reflection.Assembly]::GetAssembly([Drawing.Image]).Location) >$null
- $cp.ReferencedAssemblies.Add([Reflection.Assembly]::GetAssembly([Linq.Enumerable]).Location) >$null
- $cp.CompilerOptions ='/unsafe'
-
- Add-Type -CompilerParameters $cp -TypeDefinition @'
- using System;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Collections.Generic;
- using System.Linq;
-
- public class test
- {
- unsafe public static int main(string f)
- {
- Bitmap bitmap = new Bitmap(@f);
- int width = bitmap.Width;
- int height = bitmap.Height;
- int h = height/2;
- BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, h, width, height-h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
- byte* p = (byte*)(IntPtr)bitmapData.Scan0;
- Dictionary<int, int> b = new Dictionary<int, int>();
- for (int i = 0; i < width * (height-h) * 4; i+=4)
- {
- int c = (p[i+3] << 24) | (p[i+2] << 16) | (p[i+1] << 8) | p[i];
- b[c] = b.ContainsKey(c) ? b[c] + 1 : 1;
- }
- bitmap.UnlockBits(bitmapData);
- bitmap.Dispose();
- var d = b.OrderBy(x => x.Value).Select(x => x.Value).ToArray();
- return width*h/(d[d.Length-1]) < 30 ? 1 : 0;
- }
- }
- '@
- mkdir 123
- $a=dir *.jpg|%{if([test]::main($_.FullName)){move $_.fullname '123'}}
复制代码
|