gpt4 book ai didi

asp.net - 显示来自 Mysql 数据库的图像很慢 我该如何提高加载速度?异步

转载 作者:行者123 更新时间:2023-11-29 07:00:15 25 4
gpt4 key购买 nike

你好,我正在做一个学校项目,我有一个包含图像的页面,我正在从 MySQL 数据库中检索它,但是它以任何方式增加图像渲染都很慢?

任何帮助都会很棒 :)

我的代码

<asp:DataList ID="dlst" runat="server" DataKeyField="ProductID"  DataSourceID="SqlDataSource1" RepeatDirection="Horizontal" RepeatColumns="3" >
<HeaderTemplate>

</HeaderTemplate>

<ItemTemplate>
<asp:ImageButton ID="btnpopup" runat="server" ImageUrl='<%# "GetImage.aspx?id=" + Eval("ProductID") %>' Width="200px" Height="200px" CommandArgument='<%#Eval("ProductID") %>' CommandName="popup" CausesValidation="false" BorderStyle="Dotted" BorderColor="WhiteSmoke" />


</ItemTemplate>

</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:smokeshopConnectionString %>"
ProviderName="<%$ ConnectionStrings:smokeshopConnectionString.ProviderName %>"
SelectCommand="SELECT ProductID, Name, Description, ProductImage FROM products"></asp:SqlDataSource>

我的第二个页面叫 GetImage

string id = Request.QueryString["id"];

MySqlDataReader r = db.getImage(id);

while(r.Read())
{
byte[] imgData = (byte[])r["ProductImage"];
Response.BinaryWrite(imgData);
Response.Flush();
}

最佳答案

  • 将图像保存在您的网络服务器上,并且只将文件名保存在数据库中。它肯定会加快速度。

  • 浏览器只维护一个有限的编号。给定子域的连接数和所有图像都从同一个子域返回,因此这也可能是渲染缓慢的原因。考虑通过散列图像 ID 来生成具有不同子域(但对于给定图像相同)的每个图像标签。这将使图像下载并行。例如,static1.yourdomain.com/image1.jpg、static2.yourdomain.com/image2.jpg

  • 由于每个子域都会增加一次dns查找开销,所以一定不要添加太多的子域。

  • 不要在 html 中使用高度和宽度属性调整图像大小,而是保留已保存的 200x200(在您的情况下)图像并进行渲染。
  • 提高服务器上图像的压缩级别(取决于您可能有的图像质量要求)

关于asp.net - 显示来自 Mysql 数据库的图像很慢 我该如何提高加载速度?异步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10568965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com