Click here to Skip to main content
13,090,426 members (36,226 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello How can i convert an image into binary array ??
Posted 7-Jan-13 13:46pm
Why? And, importantly, what do you use: System.Drawing? WPF? Something else? In all cases, read on imaging there; everything else is explained.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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)
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can search for articles in the search box above. Like Convert Image File to Bytes and Back [^], for example.
Saad Mahdi Salh 7-Jan-13 20:03pm
is there some simpler solution
Christian Graus 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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2017
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