none
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. 

    $bg.add_click({
    
                $Location = $pictureBox.ImageLocation
                $OldHeight = $pictureBox.Image.Height
                write-host $OldHeight
                $OldWidth = $pictureBox.Image.Width
                write-host $OldWidth
    
                        [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms"); 
    $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()
                $bitmap.Save($tempFile);
                $pictureBox.Load($tempFile);
                $pictureBox.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::CenterImage#>
                $Bitmap.Dispose()
                $NewImage.Dispose()
                })
    Help me out guys. 

    Naveen Basati

    Thursday, February 26, 2015 3:31 AM

Answers

All replies

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

    http://1drv.ms/1AMzgFm

    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