图像:当打开的页面托管在服务器中但在本地工作时,gdi+ 中发生一般错误
本文关键字:工作 gdi+ 错误 图像 服务器 | 更新日期: 2023-09-27 18:33:46
我从数据库中获取字节并将它们转换为图像并将其发布在asp:image
中; 当页面托管在服务器中时,尽管页面在本地正常工作,但它不起作用。为什么会这样?这也不是JS错误,很可能是一个例外。
错误:gdi+ 中发生一般错误
ASP VB.NET 代码
ds = objPicturess.GetALLPicturesByCategoryIdnCusId(dplCustomer.SelectedValue, dplCategory.SelectedValue, dtpFromDate.Date, dtpToDate.Date)
If ds.Tables(0).Rows.Count <> 0 Then
For i = 0 To ds.Tables(0).Rows.Count - 1
Dim imageContent As Byte() = DirectCast((ds.Tables(0).Rows(i)("Picture")), Byte())
byteArrayToImage(imageContent, ds.Tables(0).Rows(i)("PictureTitle"), ds.Tables(0).Rows(i)("Remarks"))
'Response.BinaryWrite(imageContent)
Next
DataList1.DataSource = dt
DataList1.DataBind()
Else
DataList1.DataSource = Nothing
DataList1.DataBind()
End If
Public Sub byteArrayToImage(ByVal byteArrayIn As Byte(), ByVal strFile_Name As String, ByVal strRemarks As String)
Try
Dim newImage As System.Drawing.Image
Dim strFileName2 As String
strPictureTitle = ""
strPictureTitle = strFile_Name
strFileName = ""
strFileName = "~/PictureGallery/" & strFile_Name & ".jpg"
strFileName2 = Server.MapPath("~/PictureGallery/" & strFile_Name & ".jpg")
Dim f As New IO.FileInfo(strFileName)
If Not f.Exists Then
Using stream As New MemoryStream(byteArrayIn)
newImage = System.Drawing.Image.FromStream(stream)
newImage.Save(strFileName2)
End Using
End If
dr = dt.NewRow()
dr("PictureTitle") = strPictureTitle
dr("Picture") = strFileName
dr("Remarks") = strRemarks
dt.Rows.Add(dr)
Catch ex As Exception
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "message", "alert('" + ex.Message + "');", True)
End Try
End Sub
ASPx 代码
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Font-Bold="True" Text ='<%# Eval("PictureTitle")%>'
Font-Size="10pt" ForeColor="#336699" Width="100%" />
<br />
<asp:ImageMap BorderWidth="1px" BorderColor="Black" runat="server" Height = "175px" ID="imageZoom" Width = "172px" ImageUrl= '<%# Eval("Picture")%>' StyleFolder="styles/simple" BigImageUrl='<%# Eval("Picture")%>'/>
<br />
<asp:Label ID="lblRemarks" runat="server" Font-Bold="True" Text ='<%# Eval("Remarks")%>' Font-Size="10pt" ForeColor="#336699" Width="100%" />
</ItemTemplate>
您可以直接通过 IIS 访问文件夹安全性/权限:
- Open inetmgr (start> run> inetmgr(
- 展开站点并右键单击要写入图像的文件夹
- 点击"编辑权限">
- 转到"安全"选项卡
- 将相应的帐户添加到授权用户列表和/或确保该帐户具有写入权限。
- 应用更改
从 IIS 授予对文件夹的权限