Kann mir jemand bei meinem komischen fehler helfen?

  • VB.NET

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von EugenIS.

    Kann mir jemand bei meinem komischen fehler helfen?

    Hallo, ich habe hier ein kleines problem, und komme nicht drauf wocher das kommt:

    hab eine webcam, da nehme ich ein bild mit auf:

    Quellcode

    1. Friend Function getBmp1() As Bitmap
    2. PictureBox1.Image = webcam.CapturePicture(webcam.videoHandle)
    3. Return PictureBox1.Image
    4. End Function


    so, das bild ist in der picbox1. so jetzt will ich das bild binär haben und picbox2 abspeichern. damit ich das bild binärisieren kann, hab ich das in einen neuen bild kopiert:

    ps. funkt2 zeigt auf die getBmp1()

    Quellcode

    1. bmp_origenal = owner.Invoke(funk2)
    2. bmp_binaer = bmp_origenal
    3. bmp_new = bmp_origenal
    4. bmp_old = bmp_origenal


    so, so weit so gut. jetzt habe ich zwei bilder, in zwei picboxen. das eine ist farbig, das andere binär.

    jetzt kommt meine frage:

    wenn ich jetzt das binäre bild noch einmal kopiere und damit noch was mache, ändert es die picbox2 und picbox3. und ich komm nicht auf dem fehler. mein hintergrundprozess sieht so aus:

    ich habe sogar schon einfach mal zu probe:bmp_new = bmp_origenal, und danach mache ich mit dem bmp_new nichts und dennoch zeigt er beide picboxen (2 und 3) das binäre bild.

    Quellcode

    1. Dim funk1 As New funktion1(AddressOf owner.changBild)
    2. Dim funk2 As New funktion2(AddressOf owner.getBmp1)
    3. Dim bmp_origenal As Bitmap
    4. Dim bmp_binaer As Bitmap
    5. Dim bmp_old As Bitmap
    6. Dim bmp_new As Bitmap
    7. Dim x, y As System.Drawing.Color
    8. Dim i, j, r, g, b, ans, h As Integer
    9. Dim erkannt As Boolean = False
    10. 'owner.PictureBox2.Image = owner.webcam.CapturePicture(owner.webcam.videoHandle)
    11. bmp_origenal = owner.Invoke(funk2)
    12. bmp_binaer = bmp_origenal
    13. bmp_new = bmp_origenal
    14. bmp_old = bmp_origenal
    15. While True
    16. bmp_origenal = owner.Invoke(funk2)
    17. bmp_binaer = bmp_origenal
    18. bmp_new = bmp_origenal
    19. i = 0
    20. Do
    21. Do
    22. x = bmp_binaer.GetPixel(j, i)
    23. r = Convert.ToInt16(x.R)
    24. g = Convert.ToInt16(x.G)
    25. b = Convert.ToInt16(x.B)
    26. If r > 250 And erkannt = False Then
    27. x = Color.FromArgb(255, 0, 0)
    28. bmp_binaer.SetPixel(j, i, x)
    29. For h = -10 To 10
    30. If (j + h > 0) And (j + h < bmp_binaer.Width) Then bmp_binaer.SetPixel(j + h, i, x)
    31. If (i + h > 0) And (i + h < bmp_binaer.Height) Then bmp_binaer.SetPixel(j, i + h, x)
    32. Next
    33. erkannt = True
    34. Else
    35. ans = ((r + (g + b)) / 3)
    36. If (ans > 128) Then
    37. r = 255
    38. g = 255
    39. b = 255
    40. Else
    41. r = 0
    42. g = 0
    43. b = 0
    44. End If
    45. x = Color.FromArgb(r, g, b)
    46. bmp_binaer.SetPixel(j, i, x)
    47. End If
    48. j += 1
    49. Loop While j < bmp_binaer.Width
    50. j = 0
    51. i += 1
    52. Loop While i < bmp_binaer.Height
    53. For i = -50 To 50
    54. bmp_binaer.SetPixel(bmp_binaer.Width / 2 + i, bmp_binaer.Height / 2, Color.Blue)
    55. bmp_binaer.SetPixel(bmp_binaer.Width / 2, bmp_binaer.Height / 2 + i, Color.Blue)
    56. Next
    57. erkannt = False
    58. bmp_new = bmp_origenal
    59. Do
    60. Do
    61. x = bmp_new.GetPixel(j, i)
    62. 'y = bmp_old.GetPixel(j, i)
    63. If x <> y Then
    64. x = Color.FromArgb(255, 255, 255)
    65. 'bmp_new.SetPixel(j, i, x)
    66. End If
    67. j += 1
    68. Loop While j < bmp_binaer.Width
    69. j = 0
    70. i += 1
    71. Loop While i < bmp_binaer.Height
    72. owner.Invoke(funk1, bmp_origenal, bmp_binaer, bmp_new)
    73. End While
    74. End Sub


    kann mir jemand helfen?
    Bitmap ist eine Klasse, damit ein Referenztyp. Beim Zuweisen mit = wird lediglich die Referenz kopiert (zwei Variablen zeigen auf das gleiche Bitmap). Um ein eigenständiges Bitmap zu erstellen, nimmt den Bitmap-Konstruktor, der ein Vorlage-Bitmap erwartet.
    PS: Das ist eine Vermutung, ich kann daher nichts garantieren.

    Viele Grüße, Phil.