Hallo,
ich hab ein kleines Problem mit meinem Programm. Ich habe ein Formular, in dem unter anderem eine Picturebox enthalten ist. Inhalt der Picturebox ist ein aus einer Datenbank ausgelesenes Bild, das in der Größe an die Picturebox angepasst wird und temporär gespeichert wird. Wenn ich nun in diesem Formular einer der Tasten Tab, Alt oder AltGr drücke stürzt es mit der Fehlermeldung
"Eine nicht behandelte Ausnahme des Typs 'System.ArgumentException' ist in system.windows.forms.dll aufgetreten.
Zusätzliche Informationen: Ungültiger Parameter verwendet."
ab. Der betreffende Code lautet:
Private Sub bild()
Dim fs As IO.FileStream
Dim bw As IO.BinaryWriter
Dim bufferSize As Integer = 100
Dim outbyte(bufferSize - 1) As Byte
Dim retval As Long
Dim startIndex As Long = 0
Dim myreader As OracleClient.OracleDataReader
Dim reader As Int32
OC_bild.Connection = prnt.MyConnection
OC_bild.CommandText = "select bild from befund where befund_id = '" & _
txt_Befund_ID.Text & "'"
myreader = OC_bild.ExecuteReader(CommandBehavior.SequentialAccess)
OC_bild.CommandText = "select befund_id from befund where bild is not" & _
"null and befund_id = '" & txt_Befund_ID.Text & "'"
reader = OC_bild.ExecuteScalar
If reader = txt_Befund_ID.Text Then
If IO.File.Exists("bild.jpg") = True Then
IO.File.Delete("bild.jpg")
End If
Do While myreader.Read()
fs = New IO.FileStream("bild.jpg", IO.FileMode.OpenOrCreate, _
IO.FileAccess.Write)
bw = New IO.BinaryWriter(fs)
startIndex = 0
retval = myreader.GetBytes(0, startIndex, outbyte, 0, _
bufferSize)
Do While retval = bufferSize
bw.Write(outbyte)
bw.Flush()
startIndex += bufferSize
retval = myreader.GetBytes(0, startIndex, outbyte, 0, _
bufferSize)
Loop
bw.Write(outbyte, 0, retval - 1)
bw.Flush()
bw.Close()
fs.Close()
Loop
myreader.Close()
Dim img As Image = Image.FromFile("bild.jpg")
Dim bild As Image
Dim maxwidth, maxheight As Integer
Dim callback As System.Drawing.Image.GetThumbnailImageAbort
maxwidth = 256
maxheight = 184
bild = CalculateThumbnailSize(img, maxwidth, maxheight)
PB_bild.SizeMode = PictureBoxSizeMode.CenterImage
PB_bild.Image = bild
PB_bild.Refresh()
img.Dispose()
bild.Dispose()
Else
PB_bild.Image = Image.FromFile("na.gif")
PB_bild.Refresh()
End If
End Sub Und zur Berechnung der Bildgröße:
Private Function CalculateThumbnailSize(ByRef Img As Image, ByVal MaxWidth As _
Integer, ByVal MaxHeight As Integer) As Image
Static tWidth As Integer, tHeight As Integer
Dim Ratio As Single
Dim I As Single
Dim bild As Image
If Img Is Nothing Then Exit Function
If Img.Width / MaxWidth > Img.Height / MaxHeight Then
If tWidth <> 96 Then
Ratio = Img.Width / Img.Height
tWidth = Img.Width / (Img.Width / MaxWidth)
tHeight = tWidth / Ratio
End If
Else
If tHeight <> 96 Then
Ratio = Img.Height / Img.Width
tHeight = Img.Height / (Img.Height / MaxHeight)
tWidth = tHeight / Ratio
End If
End If
bild = Img.GetThumbnailImage(tWidth, tHeight, Nothing, Nothing)
Return bild
End Function Woran kann das liegen??? |