System.Runtime.InteropServices.ExternalException:GDI +中发生一般错误。恶魔

时间:2012-03-29 11:01:33

标签: asp.net

hye ....有点紧急...... 我使用临时文件夹来存储预览图像,当我尝试保存它们时,System.Runtime.InteropServices.ExternalException:报告GDI + erreo中发生一般错误... 如果是FileUpload1.HasFile那么             Dim path As String = Server.MapPath(“./ TempImages /”)             Dim oFileInfo作为新的FileInfo(FileUpload1.PostedFile.FileName)

        Dim fileName As String = oFileInfo.Name

        Dim fullFileName As String = path + "\\" + fileName
        Dim imagePath As String = "TempImages/" + fileName

        If Not Directory.Exists(path) Then
            Directory.CreateDirectory(path)
        End If

        FileUpload1.PostedFile.SaveAs(fullFileName)
        Image1.ImageUrl = imagePath

这就是我正在做的事情和保存

If(FileUpload1.HasFile)然后                 Dim strextension As String = System.IO.Path.GetExtension(FileUpload1.FileName)                 如果(strextension.ToUpper()=“.JPG”)那么

                Dim imagetoberezised As System.Drawing.Image = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream)
                Dim imageheight As Integer = imagetoberezised.Height
                Dim imagewidth As Integer = imagetoberezised.Width
                Dim maxheight As Integer = 120
                Dim maxwidth As Integer = 80
                imageheight = (imagewidth * maxheight) / imageheight
                imagewidth = maxheight
                If imageheight > maxheight Then
                    imageheight = (imagewidth * maxheight) / imageheight
                    imagewidth = maxheight


                End If
                Dim bitmap As New Bitmap(imagetoberezised, imagewidth, imageheight)
                Dim stream As System.IO.MemoryStream = New MemoryStream()
                bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg)
                stream.Position = 0
                Dim img As Byte() = New Byte(stream.Length) {}
                stream.Read(img, 0, img.Length)
                Dim conn5 As New SqlConnection
                conn5 = New SqlConnection
                conn5.ConnectionString = "Server=aa-pc;Database=abcc;Uid=sa;Pwd=sa@123;"
                Try
                    conn5.Open()
                    Dim sql As String = "update abcset abc_IMAGE = @eimg where PART_NO=" & Val(Part_List.SelectedValue)
                    Dim cmd5 As SqlCommand = New SqlCommand(sql, conn5)
                    Dim uploadimage As New SqlParameter("@eimg", SqlDbType.Image, img.Length)
                    uploadimage.Value = img
                    cmd5.Parameters.Add(uploadimage)
                    Dim id As Integer = Convert.ToInt32(cmd5.ExecuteScalar())




                Catch
                    MsgBox("error")

                Finally
                    conn5.Close()

                End Try

            End If
        End If

它在我们在本地运行它但在服务器上运行时效果很好。

1 个答案:

答案 0 :(得分:0)

试试这个,它对我有用:

Dim path As String = Server.MapPath("~/TempImages")

Dim FileInfo As New IO.FileInfo(FileUpload1.PostedFile.FileName)
Dim fileName As String = FileInfo.Name


'sets the image path

Dim fullFileName As String = path + "\" + fileName
Dim imagePath As String = "TempImages/" + fileName

'If Not Directory.Exists(path) Then

If Not System.IO.Directory.Exists("directory path") Then
    System.IO.Directory.Exists("directory path")
End If

FileUpload1.PostedFile.SaveAs(fullFileName)
Image1.ImageUrl = imagePath