酷代码 AI
菜单
服务商
DeepSeek字节豆包讯飞星火
更多选项

用 PowerShell 脚本轻松修复老照片:亮度与对比度调整示例

以下是一个简单的 PowerShell 脚本示例,用于对老照片进行一些基本的处理(假设这里是调整亮度和对比度): ```powershell # 加载图片处理模块 Add-Type -AssemblyName System.Drawing # 定义输入和输出文件路径 $inputImagePath = "oldPhoto.jpg" $outputImagePath = "newPhoto.jpg" # 读取图片 $image = [System.Drawing.Image]::FromFile($inputImagePath) # 调整亮度(这里增加 50) $brightness = 50 $adjustedImage = New-Object System.Drawing.Bitmap($image.Width, $image.Height) $graphics = [System.Drawing.Graphics]::FromImage($adjustedImage) $graphics.DrawImage($image, 0, 0) $colorMatrix = [System.Drawing.Imaging.ColorMatrix] @( (1, 0, 0, 0, $brightness), (0, 1, 0, 0, $brightness), (0, 0, 1, 0, $brightness), (0, 0, 0, 1, 0) ) $imageAttributes = New-Object System.Drawing.Imaging.ImageAttributes $imageAttributes.SetColorMatrix($colorMatrix) $graphics.DrawImage($image, New-Object System.Drawing.Rectangle(0, 0, $image.Width, $image.Height), 0, 0, $image.Width, $image.Height, [System.Drawing.GraphicsUnit]::Pixel, $imageAttributes) # 调整对比度(这里增加 50) $contrast = 50 $contrastValue = ($contrast + 100) / 100 $colorMatrix = [System.Drawing.Imaging.ColorMatrix] @( ($contrastValue, 0, 0, 0, 0), (0, $contrastValue, 0, 0, 0), (0, 0, $contrastValue, 0, 0), (0, 0, 0, 1, 0) ) $imageAttributes.SetColorMatrix($colorMatrix) $graphics.DrawImage($image, New-Object System.Drawing.Rectangle(0, 0, $image.Width, $image.Height), 0, 0, $image.Width, $image.Height, [System.Drawing.GraphicsUnit]::Pixel, $imageAttributes) # 保存处理后的图片 $adjustedImage.Save($outputImagePath) ``` 注意: 1. 实际应用中可能需要更复杂的图像处理算法和参数调整。 2. 处理大型图片时,性能可能是一个问题,需要考虑优化。 3. 确保输入的图片路径存在且有权限访问。 ######[AI写代码神器 | 618点数解答 | 2025-02-10 00:56:44]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]