cs_tx_usa 0 Light Poster

Hi, I've been working on a program that reads two binary files, then each value of file1 is divided by each value of file2. My binary files are 8-bit grayscale image files that is each pixel has a value between 0 and 255. I read them into byte arrays.

I am having a major problem. Since I read both input files into byte arrays, I am going to have a problem when the values of file 1 is divided by the values of file 2. The result should be type Double right? and I dont know how to write the output into a seperate file. How could I resolve this? Please help me on this because it gives me too much headache

'OK button
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If TextBox1.Text.Length = 0 Then
            MessageBox.Show("You should select a file first!", "Warning!")
            Me.Button1.Focus()
        Else

            '==========================================
            Dim s1 As FileStream 'Load file 1
            Dim s2 As FileStream 'Load file 2
            Dim s3 As FileStream 'Save output


            '---read from and write to a binary file
            s1 = New FileStream(textbox1.text, FileMode.Open, FileAccess.Read)
            s2 = New FileStream(textbox2.text, FileMode.Open, FileAccess.Read)
            s3 = New FileStream(saveFD.FileName, FileMode.CreateNew, FileAccess.Write)

            Dim fLen1 As Integer
            Dim fLen2 As Integer
            Dim f1 As New System.IO.FileInfo(textbox1.text)
            Dim f2 As New System.IO.FileInfo(textbox2.text)
            fLen1 = f1.Length
            fLen2 = f2.Length
 
            Dim byteRead1(fLen1) As Byte
            Dim byteRead2(fLen2) As Byte
            Dim dblOutput(fLen1) As Double 'wıll hold results from division
            Dim i As Integer
            Dim j As Integer
            Dim k As Integer
            Dim m As Integer
           
            'Read binary file1 and fill the array with pixel values 
            For i = 0 To fLen1 - 1
                byteRead1(i) = s1.ReadByte
            Next

            'Read binary file2 and fill the array with pixel values
            For j = 0 To fLen2 - 1
                byteRead2(j) = s2.ReadByte

            Next

            'Test to see if the values read and assigned correctly
            For k = 0 To 13 'I used this just for testing purposes

                MsgBox("byteRead1(" & k & ")= " & byteRead1(k))
                MsgBox("byteRead2(" & k & ")= " & byteRead2(k))
            Next
 
            For m = 0 To fLen2 - 1
'check the vals for division by 0

                If byteRead1(m) = 0 Or byteRead2(m) = 0 Then
                      byteRead3(intI) = 0
                Else 
                     'no division error, get the val to write
                      dblOutput(m) = (byteRead1(m) / byteRead2(m)) 
                End If
                     'write the val
                     'streamOut.Write(dblOutput) 'this won't work 
                            Next
                     's3.Write(dblOutput) 'this won't work either

'On above For Next loop, can type BYTE be converted into type Double?
'I don't know how to write dblOutput array into a file CORRECTLY
'Please HELP me how to write dblOutput into a file

            s1.Close()
            s2.Close()
            s3.Close()
              '===========================================
             MessageBox.Show("Process Completed!", "Done")
            Me.Close()
        End If
       
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.