Ok this is fully functioning and tested by outputting stored pixels back out and verified image is correct.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
ComparePixelReads()
End Sub
Public Sub ComparePixelReads()
Try
Using sw As New System.IO.StreamWriter("D:\pixeltest\pixeloutput.txt", False)
Dim tmp As System.Drawing.Bitmap = System.Drawing.Bitmap.FromFile("D:\pixeltest\ManagerPanel.bmp")
Dim jImg As System.Drawing.Bitmap = ConvertToRGB(tmp)
Dim jc2(jImg.Height, jImg.Width) As System.Drawing.Color
Dim jc3(jImg.Height, jImg.Width) As System.Drawing.Color
For i As Integer = 0 To jImg.Height - 1
For j As Integer = 0 To jImg.Width - 1
Dim cl As System.Drawing.Color = jImg.GetPixel(j, i)
jc2(i, j) = cl
Next
Next
Dim bd As System.Drawing.Imaging.BitmapData = jImg.LockBits(New System.Drawing.Rectangle(0, 0, jImg.Width, jImg.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
Dim sourceBuffer((bd.Stride * bd.Height)) As Byte
System.Runtime.InteropServices.Marshal.Copy(bd.Scan0, sourceBuffer, 0, sourceBuffer.Length)
jImg.UnlockBits(bd)
Dim st As Integer = 0
Dim bb, bg, br, ba As Integer
For i As Integer = 0 To jImg.Height - 1
st = bd.Stride * i
For j As Integer = 0 To jImg.Width - 1
bb = sourceBuffer(st)
bg = sourceBuffer(st + 1)
br = sourceBuffer(st + 2)
ba = sourceBuffer(st + 3)
jc3(i, j) = System.Drawing.Color.FromArgb(ba, br, bg, bb)
st += 4
Next
Next
Dim outputCompare1 As New System.Drawing.Bitmap(jImg.Width, jImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
Dim outputCompare2 As New System.Drawing.Bitmap(jImg.Width, jImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
If (jc2.Length = jc3.Length) Then
For y As Integer = 0 To jImg.Height - 1
For x As Integer = 0 To jImg.Width - 1
outputCompare1.SetPixel(x, y, jc2(y, x))
outputCompare2.SetPixel(x, y, jc3(y, x))
sw.WriteLine(String.Format("PixelGet: {0} LockBitsGet: {1}", "(" & y.ToString() & ", " & x.ToString() + ")" & jc2(y, x).ToArgb().ToString(), "(" & y.ToString() & ", " & x.ToString() & ")" & jc3(y, x).ToArgb().ToString()))
Next
Next
End If
outputCompare1.Save("D:\pixeltest\jc2.bmp")
outputCompare2.Save("D:\pixeltest\jc3.bmp")
End Using
Catch ex As Exception
MessageBox.Show(ex.Message & vbCrLf & ex.StackTrace)
End Try
End Sub
Public Function ConvertToRGB(ByVal original As Bitmap) As Bitmap
If original.PixelFormat = Imaging.PixelFormat.Format32bppArgb Then Return original
Dim newImage As Bitmap = New Bitmap(original.Width, original.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
newImage.SetResolution(original.HorizontalResolution, original.VerticalResolution)
Dim g As Graphics = Graphics.FromImage(newImage)
g.DrawImageUnscaled(original, 0, 0)
g.Dispose()
Return newImage
End Function