【发布时间】:2021-05-31 18:03:32
【问题描述】:
我有一个从给定文件夹中读取 jpg 文件的脚本。我想在 PictureBox 中显示它们。但是会发生什么:图片没有旋转。为了解决这个问题,我创建了以下脚本:
Function Get-Orientation
{
<#
.NOTES
=============================================================================================================================================
Created with: Windows PowerShell ISE
Created on: 30-May-2021
Created by: Willem-Jan
Organization:
Functionname: Get-Orientation
=============================================================================================================================================
.SYNOPSIS
This function reads the orientation of a picture.
#>
Param
(
[String] $SourceFileName
)
$img = New-Object -TypeName system.drawing.bitmap -ArgumentList $SourceFileName
$IMGOrientation = ($img.PropertyItems | Where {($_.ID -eq 274)}).Value[0]
Return $IMGOrientation
}
ForEach ($JPGFileName in $JPGFileNames)
{
$Orientation = Get-Orientation -SourceFileName $($JPGFileName.FullName)
$pbPicturePreview.Image = [System.Drawing.Bitmap]$($JPGFileName.FullName)
if($Orientation = 2) {$pbPicturePreview.Image.RotateFlip("RotateNoneFlipX")}
if($Orientation = 3) {$pbPicturePreview.Image.RotateFlip("RotateNoneFlipXY")}
if($Orientation = 4) {$pbPicturePreview.Image.RotateFlip("RotateNoneFlipY")}
if($Orientation = 5) {$pbPicturePreview.Image.RotateFlip("Rotate90FlipX")}
if($Orientation = 6) {$pbPicturePreview.Image.RotateFlip("Rotate90FlipNone")}
if($Orientation = 7) {$pbPicturePreview.Image.RotateFlip("Rotate90FlipY")}
if($Orientation = 8) {$pbPicturePreview.Image.RotateFlip("Rotate90FlipXY")}
}
不相关的代码部分已被删除。
如果我将 $pbPicturePreview.Image.RotateFlip("Rotate90FlipXY") 更改为 $pbPicturePreview.Image.RotateFlip("RotateFlipType.Rotate90FlipXY") 则会收到一条错误消息,指出“RotateFlipType.Rotate90FlipXY”不受支持。
我使用https://docs.microsoft.com/en-us/dotnet/api/system.drawing.image.rotateflip?view=net-5.0 和Getting correct Image rotation 作为来源。还有其他页面。
我可以做些什么来确保正确旋转的图片显示在图片框中?任何帮助表示赞赏。
致以诚挚的问候, 威廉-扬
【问题讨论】:
-
$pbPicturePreview.Image.RotateFlip([System.Drawing.RotateFlipType]::Rotate90FlipXY) -
很抱歉,您的解决方案没有解决这个问题。
-
如果将枚举名称
Rotate90FlipXY替换为其数值3会发生什么? -
或尝试
[System.Drawing.RotateFlipType]::Rotate270FlipNone与3具有相同的值
标签: powershell