0

I have a script that reads the jpg files from a given folder. I want to display them in a PictureBox. But what happens: the picture is not rotated. To handle this, I created the following script:

  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")}
     }

The not-relevant code part has been removed.

If I change $pbPicturePreview.Image.RotateFlip("Rotate90FlipXY") to $pbPicturePreview.Image.RotateFlip("RotateFlipType.Rotate90FlipXY") then I receive an error message stating that "RotateFlipType.Rotate90FlipXY" is not supported.

I used https://learn.microsoft.com/en-us/dotnet/api/system.drawing.image.rotateflip?view=net-5.0 and Getting correct Image rotation as source. But also other pages.

What can I do to make sure that the picture in the correct rotation is shown in the picturebox? Any help is appreciated.

With kind regards, Willem-Jan

1 Answers1

0

I have found the issue. The error is the part:

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

It should be:

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

I am so sorry... :-( Sometimes, I am messing up all the languages.

With kind regards, Willem-Jan