Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
Hello How can i convert an image into binary array ??
Posted 7-Jan-13 13: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.
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 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 OriginalGriff 370
1 Sergey Alexandrovich Kryukov 195
2 Prakriti Goyal 177
3 jlopez788 134
4 _Amy 110
0 OriginalGriff 6,762
1 Sergey Alexandrovich Kryukov 5,539
2 Maciej Los 3,479
3 Peter Leow 3,323
4 DamithSL 2,505

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