SHARE
TWEET

[Swen Kooij] Image Converter in VB.NET

Ortund Feb 11th, 2014 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System
  2. Imports System.IO
  3. Imports System.Drawing
  4. Imports System.Imaging
  5.  
  6. Public Class ImageConverter
  7.  
  8.         Public Static Function ImageToBytes(ByVal img As Image) As byte()
  9.                 If img Is Nothing Then
  10.                         Return Nothing
  11.                 Else
  12.                         Dim memstream As New MemoryStream()
  13.                         img.Save(memstream, img.RawFormat)
  14.  
  15.                         Dim img_raw As byte() = memstream.ToArray()
  16.  
  17.                         memstream.Dispose()
  18.                         return img_raw
  19.                 End If
  20.         End Function
  21.  
  22.         Public Static Funtion BytesToImage(ByVal img_raw As byte()) As Image
  23.                 If img_raw Is Nothing Then
  24.                         Return Nothing
  25.                 End If
  26.  
  27.                 Dim memstream As New MemoryStream(img_raw)
  28.                 Dim img As New Image = Image.FromStream(memstream)
  29.  
  30.                 memstream.Dispose()
  31.  
  32.                 Return img
  33.         End Function
  34. End Class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top