Ho fatto uno script che prende delle immagini che ho in svariate cartelle e dopo averle ridimensionate le salva ma al momento di salvare mi da quest'errore
System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
sulla riga:
newImage.Save(destPath, ImageFormat.Gif)
Ecco lo script:
!------------------------------------------------
<%@ Import Namespace="System.Drawing"%>
<%@ Import Namespace="System.Drawing.Imaging"%>
<%@ Import Namespace="System.Data.Odbc"%>
<%@ Import Namespace="System.Runtime.InteropServices"%>
<%@ Import Namespace="System.IO"%>
Sub Page_Load(sender as Object,e as EventArgs)
response.contenttype="image/gif"
Dim destPath as String
Dim MemStream As New MemoryStream()
Dim i, j, n_foto, n_case, height, width as Integer
Dim oldImage, newImage as System.Drawing.Image
Dim myConnection = new OdbcConnection("DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=xxxxxx; UID=xxxxxx; PASSWORD=xxxxxx; OPTION=3")
myConnection.Open()
Dim myCommand as OdbcCommand
myCommand= new OdbcCommand("SELECT COUNT(*) FROM tabella", myConnection)
n_case = myCommand.ExecuteScalar()
For i = 1 to n_case
myCommand = new OdbcCommand("SELECT campo FROM tabella WHERE house_num=" & i & ";", myConnection)
n_foto = myCommand.ExecuteScalar()
if n_foto <> 0 then
For j=1 to n_foto
oldImage = System.Drawing.Image.FromFile( Server.MapPath("archivio/rurale/" & i & "/foto" & j & ".gif"))
if oldImage.width>550 then
width=150
height=105
else
width=105
height=150
end if
destPath="archivio/rurale/" & i & "/foto" & j & "_min.gif"
newImage = oldImage.GetThumbnailImage( width, height, nothing, IntPtr.Zero)
newImage.Save(destPath, ImageFormat.Gif)
next j
end if
next i
End Sub
!--------------------------------------
Se mi poteste aiutare ve ne sarei molto grato!

Rispondi quotando