Skip to content

Instantly share code, notes, and snippets.

@maxmoore14
Created October 9, 2014 14:25
Show Gist options
  • Save maxmoore14/3d4061d9a92297aa8f3e to your computer and use it in GitHub Desktop.
Save maxmoore14/3d4061d9a92297aa8f3e to your computer and use it in GitHub Desktop.
Resize an image
Public Function ResizeImage(fs As FileStream,
width As Integer,
Optional height As Integer = 0) As MemoryStream
Dim img As New BitmapImage
Dim enc As New PngBitmapEncoder
Dim ms As New MemoryStream
img.BeginInit()
img.StreamSource = fs
img.DecodePixelWidth = width
If height > 0 Then
img.DecodePixelHeight = height
End If
img.EndInit()
enc.Frames.Add(BitmapFrame.Create(img))
enc.Save(ms)
ms.Seek(0, SeekOrigin.Begin)
Return ms
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment