io utilizzo questo codice che funziona benissimo su file jpg :
codice:
rivate Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ServerClick
Dim foto As System.Drawing.Image
foto = System.Drawing.Image.FromStream(File1.PostedFile.InputStream)
Dim fotodamodificare As System.Drawing.Graphics
fotodamodificare = fotodamodificare.FromImage(foto)
' Scelgo la font e le dimensioni della scritta
Dim drawFont As Font
Dim Pennello As Brush
drawFont = New Font("Verdana", 16, FontStyle.Bold)
Pennello = New SolidBrush(Color.FromArgb(200, 255, 255, 90))
Dim drawPoint As New PointF(0.5F, 0.5F)
fotodamodificare.DrawString("LBJSHOP", drawFont, Pennello, drawPoint)
Dim mystream As New System.IO.MemoryStream
foto.Save(mystream, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim fotomodificata As System.Drawing.Image
fotomodificata = fotomodificata.FromStream(mystream)
fotomodificata.Save(Server.MapPath("public/result.jpg"))
fotodamodificare.Dispose()
Response.Write("ciao")
End Sub
sui file gif mi da questo errore:
A Graphics object cannot be created from an image that has an indexed pixel format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Exception: A Graphics object cannot be created from an image that has an indexed pixel format.
Source Error:
Line 31: foto = System.Drawing.Image.FromStream(File1.PostedFile.I nputStream)
Line 32: Dim fotodamodificare As System.Drawing.Graphics
Line 33: fotodamodificare = fotodamodificare.FromImage(foto)
Line 34: ' Scelgo la font e le dimensioni della scritta
Line 35: Dim drawFont As Font