1

I've this script on my program to read R component of an image and save it on an array:

Dim citra_asli As Bitmap = New Bitmap(PictureBoxAsli.Image)


    Dim i As Integer = 0
    Dim j As Integer = 0

    Dim redValue(i, j) As Integer

    ListBox3.Items.Add("Piksel--R--G--B")
    For i = 0 To ((citra_asli.Height) - 1)
        For j = 0 To ((citra_asli.Width) - 1)
            Dim R As Integer = citra_asli.GetPixel(i, j).R
            redValue(i, j) = R
            ListBox3.Items.Add((i.ToString + ("," + (j.ToString + ("  " + (redValue(i, j).ToString))))))
        Next
    Next

unfortunately I always get this error message "Index was outside the bounds of the array.". As long as I know, the redValue() array and citra_asli bitmap have identically dimension but why the error message appear? Somebody help me please or maybe there's another method to save it on an array. Thank you and please forgive me for my poor English.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794

1 Answers1

0

This ought to be correct and i have tested it.

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    Dim citra_asli As Bitmap = New Bitmap(PictureBoxAsli.Image)
    Dim x As Integer = 0
    Dim y As Integer = 0
    Dim R As Integer = 0

    ListBox1.Items.Add("Piksel--R--G--B")
    y = citra_asli.Height
    x = citra_asli.Width
    Dim redValue(x, y) As Integer
    For y = 0 To (citra_asli.Height) - 1
        For x = 0 To (citra_asli.Width) - 1
            R = citra_asli.GetPixel(x, y).R
            redValue(x, y) = R
            ListBox1.Items.Add("[" & x.ToString & "," & y.ToString & "]  " & "(" & redValue(x, y).ToString & ",grn,blu)")
        Next
    Next
End Sub
Zeddy
  • 2,079
  • 1
  • 15
  • 23