Issue when resizing the image using powershell RRS feed

  • Question

  • Hi all,

    I am trying to re-size an image using power-shell with %value as a input parameter. When I am loading the image to the picture box and giving the value to 15%. The image is good. But when I give the next value to 200 or above the image quality is lost. 

                $Location = $pictureBox.ImageLocation
                $OldHeight = $pictureBox.Image.Height
                write-host $OldHeight
                $OldWidth = $pictureBox.Image.Width
                write-host $OldWidth
    $image = new-object System.Drawing.Bitmap $Location
                $value = [int]($numericupdown2.Value)
                $Percentage = ($value / 100)
                $height = [int]($OldHeight * $Percentage)
                $width = [int]($OldWidth * $Percentage)
                write-host $width,$height
    $bitmap = new-object System.Drawing.Bitmap  $width,$height
    $newimage = [System.Drawing.Graphics]::FromImage($bitmap)
    $newimage.CompositingMode = [System.Drawing.Drawing2D.CompositingMode]::SourceCopy
    $newimage.CompositingQuality = [System.Drawing.Drawing2D.CompositingQuality]::HighQuality
    $newImage.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::HighQuality
    $newImage.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
    $newImage.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::HighQuality
    $newimage.DrawImage($image, $(New-Object -TypeName System.Drawing.Rectangle -ArgumentList 0, 0, $width, $height))
                $tempFile = [io.path]::GetTempFileName()
                $pictureBox.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::CenterImage#>
    Help me out guys. 

    Naveen Basati

    Thursday, February 26, 2015 3:31 AM


All replies

  • Here is a complete example of how to resize a picturebox image.

    Just save and run. Click buttons to enlarge and shrink image.


    • Marked as answer by BASATI Thursday, February 26, 2015 5:29 AM
    Thursday, February 26, 2015 4:42 AM
  • Thanks jrv,

    I will check it with that. I would like to experiment with the code too...

    Any issues, I will revert you back.

    Naveen Basati

    Thursday, February 26, 2015 5:29 AM