GDI+ Fehler Windows 2000

  • VB.NET

Es gibt 14 Antworten in diesem Thema. Der letzte Beitrag () ist von Gelöschter Benutzer.

    GDI+ Fehler Windows 2000

    Hallo !

    Bekomme diese Fehlermeldung -.-
    Das Programm holt sich bilder aus einem Temp verzeichnis und schreibt den zusatztext unten links auf das Foto und speichert dieses so ab



    under Windows 7 läufts

    mfg
    Codoptimierung kommt dann wenns funktioniert :D

    VB.NET-Quellcode

    1. Imports System.IO
    2. Public Class Form1
    3. Private prc As Process
    4. Sub hund()
    5. MsgBox("Keine weiteren Bilder gefunden!", MsgBoxStyle.Information)
    6. Timer1.Start()
    7. End Sub
    8. Dim PfadAufDemDevice As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\resources\Bilderpfad.txt")
    9. Dim LW As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\resources\Laufwerkbuchstabe.txt")
    10. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    11. Dim i As Integer = 0
    12. For Each item In Directory.GetFiles(PfadAufDemDevice)
    13. i = i + 1
    14. Next
    15. If i = 0 Then
    16. Me.Hide()
    17. Else
    18. ListBox1.Items.Clear()
    19. Me.Show()
    20. Timer1.Stop()
    21. Timer2.Start()
    22. For Each item In Directory.GetFiles(PfadAufDemDevice)
    23. ListBox1.Items.Add(item)
    24. Next
    25. Try
    26. PictureBox1.Load(ListBox1.Items(0))
    27. Catch ex As Exception
    28. Timer1.Stop()
    29. Timer2.Start()
    30. MsgBox("Keine Bilder vorhanden!", MsgBoxStyle.Exclamation)
    31. End Try
    32. End If
    33. End Sub
    34. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    35. If ComboBox1.Text = "" Then
    36. MsgBox("Benutzer wählen!", MsgBoxStyle.Exclamation)
    37. Exit Sub
    38. End If
    39. Dim SpeicherPfad As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\resources\Benutzer\" & namenlabel.Text)
    40. Dim bmp As New Bitmap(PictureBox1.Image)
    41. Dim g As Graphics = Graphics.FromImage(bmp)
    42. Dim i As Integer = 1
    43. If zusatztb.Text = "" Then
    44. g.FillRectangle(Brushes.Black, New Rectangle(0, bmp.Height - (bmp.VerticalResolution - 50), 200, 50))
    45. g.FillRectangle(Brushes.Black, New Rectangle(bmp.Width - 190, 0, bmp.Width, 25))
    46. g.DrawString(DateTime.Now, New Font("Arial", 14), Brushes.White, New Point(bmp.Width - 190, 0))
    47. g.DrawString(namenlabel.Text, New Font("Arial", 20), Brushes.White, New Point(10, bmp.Height - (bmp.VerticalResolution - 60)))
    48. Else
    49. g.FillRectangle(Brushes.Black, New Rectangle(0, bmp.Height - (bmp.VerticalResolution - 50), 300, 50))
    50. g.FillRectangle(Brushes.Black, New Rectangle(0, bmp.Height - (bmp.VerticalResolution), 200, 50))
    51. g.FillRectangle(Brushes.Black, New Rectangle(bmp.Width - 190, 0, bmp.Width, 25))
    52. g.DrawString(zusatztb.Text, New Font("Arial", 20), Brushes.White, New Point(10, bmp.Height - (bmp.VerticalResolution - 60)))
    53. g.DrawString(DateTime.Now, New Font("Arial", 14), Brushes.White, New Point(bmp.Width - 190, 0))
    54. g.DrawString(namenlabel.Text, New Font("Arial", 20), Brushes.White, New Point(10, bmp.Height - bmp.VerticalResolution + 10))
    55. End If
    56. Do While File.Exists(SpeicherPfad & "\" & namenlabel.Text & "-" & i & ".jpg")
    57. i += 1
    58. Loop
    59. bmp.Save(SpeicherPfad & "\" & namenlabel.Text & "-" & i & ".jpg")
    60. Try
    61. My.Computer.FileSystem.WriteAllText("Z:\Gruppe-EDV\Mathis\Domänen Programme\Programm Logs\Foto Import.txt", vbNewLine & "[" & DateTime.Now & "] Foto wurde importiert nach " & namenlabel.Text, True)
    62. Catch ex As Exception
    63. End Try
    64. File.Delete(ListBox1.Items(0))
    65. ListBox1.Items.Remove(ListBox1.Items(0))
    66. Try
    67. PictureBox1.Load(ListBox1.Items(0))
    68. Catch ex As Exception
    69. hund()
    70. Exit Sub
    71. End Try
    72. End Sub
    73. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    74. For Each items In New System.IO.DirectoryInfo(Application.StartupPath & "\resources\Benutzer").GetFiles()
    75. ComboBox1.Items.Add(items)
    76. Next
    77. Timer1.Start()
    78. End Sub
    79. Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    80. namenlabel.Text = ComboBox1.Text
    81. End Sub
    82. Private Sub AnlegenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AnlegenToolStripMenuItem.Click
    83. Process.Start("osk.exe")
    84. Dim Name As String = InputBox("Name eingeben: ")
    85. Dim SpeicherOrt As String
    86. If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
    87. SpeicherOrt = FolderBrowserDialog1.SelectedPath
    88. End If
    89. Try
    90. My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\resources\Benutzer\" & Name, SpeicherOrt, False)
    91. For Each item In System.Diagnostics.Process.GetProcesses
    92. If item.ProcessName = "osk" Then
    93. item.Kill()
    94. End If
    95. Next
    96. MsgBox("Benutzer wurde angelegt!", MsgBoxStyle.Information)
    97. Catch ex As Exception
    98. MsgBox(ex.ToString)
    99. End Try
    100. End Sub
    101. Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    102. Dim i As Integer = 0
    103. For Each item In Directory.GetFiles(PfadAufDemDevice)
    104. i = i + 1
    105. Next
    106. If i = 0 Then
    107. Me.Hide()
    108. Else
    109. Me.Show()
    110. Timer1.Start()
    111. Timer2.Stop()
    112. End If
    113. End Sub
    114. Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
    115. e.Cancel = True
    116. End Sub
    117. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    118. Process.Start(Application.StartupPath & "\resources\readme.pdf")
    119. End Sub
    120. Private Sub zusatztb_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles zusatztb.Enter
    121. Process.Start("osk")
    122. End Sub
    123. Private Sub zusatztb_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles zusatztb.Leave
    124. For Each item In System.Diagnostics.Process.GetProcesses
    125. If item.ProcessName = "osk" Then
    126. item.Kill()
    127. End If
    128. Next
    129. End Sub
    130. Private Sub Form1_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
    131. ComboBox1.Focus()
    132. End Sub
    133. End Class
    Du scheinst ein großer Freund von Try-Catch-Blöcken zu sein. Das ist Pfui (jedenfalls in 95% aller Fälle). Zudem hast du leere Catch-Zweige, setzt Pfade blind mit & zusammen (dafür gibs Path.Combine).
    Ob in einer Listbox ein Item existiert, fragt man über die Count-Eigenschaft der Listbox.Items ab.
    Der Fehler tritt offenbar beim Speichern des Image im Button1_Click-Event statt (steht in deiner Meldung)

    Fiel Fergnügen

    Vatter
    :thumbsup: Seit 26.Mai 2012 Oppa! :thumbsup:

    kikipetro schrieb:

    Aber wie fang ich an den fehler zu suchen ?
    Try / Catch raus, wenn es knallt, hast Du einen Fehler gefunden.
    Setze einen Haltepunkt in jede Prozedur (nacheinander) und arbeite sie schrittweise durch.
    Überprüfe, ob das Programm das macht, was es machen soll. Wenn nicht: Fehler gefunden.
    Sieh Dir den Inhalt von Variablen an. Stimmt er nicht: Fehler gefunden.
    Also los :!: :thumbsup:
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    okay, fehler muss hier liegen:


    VB.NET-Quellcode

    1. Do While File.Exists(SpeicherPfad & "\" & namenlabel.Text & "-" & i & ".jpg")
    2. i += 1
    3. Loop
    4. bmp.Save(SpeicherPfad & "\" & namenlabel.Text & "-" & i & ".jpg")




    denke mal eher am speichern... aber wie soll ich das bild sonst speichern ?
    Hi
    für Pfad-Verknüpfungen verwendet man System.IO.Path.Combine oder Äquivalentes. namenlabel.Text enthält gültige Werte? Du hast Schreibrechte im spezifizierten Pfad (gabs das unter Win2000 schon?). Für mehrfache einfache String-Verknüpfungen solltest du String.Concat verwenden. Übrigens wäre es günstig, kein allgemeingültiges Try-Catch zu verwenden, sondern beim Catch-Block z.B. IOException etc. abzufragen. Die Exceptions kannst du auf der MSDN oder im Object Browser ermitteln und entsprechend darauf reagieren.

    Hier wäre z.B. der Artikel für Image.Save:
    msdn.microsoft.com/de-de/library/ktx83wah.aspx

    Image.Save-Methode (String) (System.Drawing) schrieb:

    Das Bild wurde im falschen Bildformat gespeichert.

    – oder –

    Das Bild wurde in derselben Datei gespeichert, aus der es erstellt wurde.


    Gruß
    ~blaze~