用 PowerShell 旋转或翻转图片(System.Drawing)
利用系统内置的 .NET System.Drawing 在命令行直接旋转或镜像图片。
用 [System.Drawing.Image]::FromFile 读入图片,调用 RotateFlip 并指定 RotateFlipType,再 Save 保存为新文件。
01命令
命令
$ Add-Type -AssemblyName System.Drawing; $img=[System.Drawing.Image]::FromFile('C:\Users\me\photo.jpg'); $img.RotateFlip([System.Drawing.RotateFlipType]::Rotate90FlipNone); $img.Save('C:\Users\me\photo-rot.jpg'); $img.Dispose()02作用说明
System.Drawing 随 Windows 自带,无需安装任何软件。RotateFlipType 枚举把旋转(90/180/270 度)和镜像(FlipX/FlipXY)组合在一个值里,一条命令就能把竖拍照片转为横拍。保存时建议写入新文件名,用完记得 Dispose,否则文件会被进程占用。
03风险
!注意: 直接覆盖原文件会重新压缩 JPEG 造成画质损失,先另存为新文件。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- Image Class (System.Drawing)依据: Documents Image.FromFile, Image.RotateFlip and Image.Save — the three members the one-liner chains together.
- RotateFlipType Enum (System.Drawing)依据: Lists every RotateFlipType member (Rotate90FlipNone, Rotate180FlipXY, etc.) used by Image.RotateFlip to rotate and mirror an image in place.
最后验证: 2026-09-17 · 分类: 媒体