Click here to Skip to main content
11,496,146 members (599 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
See more: VB.NET
Hello How can i convert an image into binary array ??
Posted 7-Jan-13 14:46pm
Sergey Alexandrovich Kryukov at 7-Jan-13 20:06pm
Why? And, importantly, what do you use: System.Drawing? WPF? Something else? In all cases, read on imaging there; everything else is explained.
If you use System.Drawing, you can try this code

Imports System.Drawing
Imports System.Drawing.Imaging
    Public Shared Function GetBinary(ByVal image As Image, ByVal format As ImageFormat) As Byte()
        Using ms As New System.IO.MemoryStream
            If (format Is Nothing) Then
                format = image.RawFormat ' use image original format
            End If
            image.Save(ms, format)
            Return ms.ToArray()
        End Using
    End Function


Dim binaryArray As Byte()
' Get image from PictureBox and GetBinary (use original format)
binaryArray = GetBinary(PictureBox1.Image, Nothing)
' load image from file and GetBinary (formatted to png)
binaryArray = GetBinary(Image.FromFile(sourceImageFileName), ImageFormat.Png)
' To save current binaryArray to image file:
System.IO.File.WriteAllBytes(destinationImageFileName, binaryArray)
You can search for articles in the search box above. Like Convert Image File to Bytes and Back [^], for example.
Saad Mahdi Salh at 7-Jan-13 20:03pm
is there some simpler solution
Christian Graus at 7-Jan-13 20:05pm
No, there isn't. Why should there be - that looks straightforward to me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 RyanDev 230
1 Sergey Alexandrovich Kryukov 114
2 Richard Deeming 100
3 OriginalGriff 89
4 Mostafa Asaduzzaman 59
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600

Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100