Question Bitmap to Byte Array Strange Zeros

ColtSeavers

New member
Joined
Aug 18, 2019
Messages
2
Programming Experience
Beginner
Hi,

i converted a bmp into a byte Array with a memorystream.
No proplems, working fine.
But when i'm displaying the Datas in the a datagridview there are some strange zero-values!
Here is an image:

EScreenShot.png



VB.NET:
Option Strict On
Imports System.IO

Public Class Form1
    Private Sub CmdEinlesen_Click(sender As Object, e As EventArgs) Handles CmdEinlesen.Click

        Dim Bild As Image = Image.FromFile("D:\PROGRAMMIERUNG\VISUAL_STUDIO\VISUAL_BASIC\DATA_GRID_VIEW\Dgv_Bmp_2DimArray\TestMap.bmp")

        Dim bitmapBytes As Byte()

        Using stream As New System.IO.MemoryStream
            Bild.Save(stream, Bild.RawFormat)
            bitmapBytes = stream.ToArray
        End Using

        Dim bytes2(250, 250) As Byte
        Dim zeilen As Integer = 0
        Dim spalten As Integer = 0
        Dim index As Integer = 54
        Dim triplet As String = Nothing

        For i As Integer = 54 To bitmapBytes.Length - 1
            DgvDaten.Rows.Add({bitmapBytes(i)})
        Next

    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        For spalte As Integer = 0 To 23
            DgvDaten.Columns.Add("Spalte" & (spalte + 1), "Spalte" & (spalte + 1))
        Next

    End Sub
End Class

In the attachment yo will find my little project.

Hope you can help me!

Best regards;
ColtSeavers
 

Attachments

ColtSeavers

New member
Joined
Aug 18, 2019
Messages
2
Programming Experience
Beginner
@jmcilhinney


VB.NET:
        Dim Bild() As Byte = File.ReadAllBytes("D:\PROGRAMMIERUNG\VISUAL_STUDIO\VISUAL_BASIC\DATA_GRID_VIEW\Dgv_Bmp_2DimArray\TestMap5.bmp")

        Dim bitmapBytes As Byte()

        Using stream As New System.IO.MemoryStream
            Bild.Save(stream, Bild.RawFormat)
            bitmapBytes = stream.ToArray
        End Using
I need the Image object because of it's .Save and .RawFormat!!!!

Can you give me the 5 rows of code with using File.ReadAllBytes ?

Best regards,
Colt Seavers
 
Top Bottom