【问题标题】:Imagebox does not flip an image when needed with Powershell使用 Powershell 需要时,Imagebox 不会翻转图像
【发布时间】: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.0Getting correct Image rotation 作为来源。还有其他页面。

我可以做些什么来确保正确旋转的图片显示在图片框中?任何帮助表示赞赏。

致以诚挚的问候, 威廉-扬

【问题讨论】:

  • $pbPicturePreview.Image.RotateFlip([System.Drawing.RotateFlipType]::Rotate90FlipXY)
  • 很抱歉,您的解决方案没有解决这个问题。
  • 如果将枚举名称 Rotate90FlipXY 替换为其数值 3 会发生什么?
  • 或尝试[System.Drawing.RotateFlipType]::Rotate270FlipNone3具有相同的值

标签: powershell


【解决方案1】:

我找到了问题。错误是部分:

if($Orientation = 6) {$pbPicturePreview.Image.RotateFlip("Rotate90FlipNone")}

应该是:

if($Orientation -eq 6) {$pbPicturePreview.Image.RotateFlip("Rotate90FlipNone")}

我很抱歉... :-( 有时,我把所有语言都搞砸了。

诚挚的问候, 威廉-扬

【讨论】:

    猜你喜欢
    • 2013-09-17
    • 1970-01-01
    • 1970-01-01
    • 2019-05-13
    • 1970-01-01
    • 2011-07-12
    • 1970-01-01
    • 2017-06-24
    • 2012-03-22
    相关资源
    最近更新 更多