Created
October 9, 2014 14:25
-
-
Save maxmoore14/3d4061d9a92297aa8f3e to your computer and use it in GitHub Desktop.
Resize an image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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