gpt4 book ai didi

java - 如何创建一个从 Glide 请求图像发送图像的服务器?

转载 作者:行者123 更新时间:2023-12-01 11:11:29 24 4
gpt4 key购买 nike

我使用 Glide 作为客户端的图像加载器。我用 java 创建了自己的服务器。

我的服务器代码:

            File f = new File(imageLocation);
try{
bi = ImageIO.read(f);
}catch (Exception e){
f = new File(imageLocation);
bi = ImageIO.read(f);
}


respond = "HTTP/1.1 200 OK\r\n";
respond += "Date: " + LocalDateTime.now() + "\r\n";
respond += "Content-Type: image/png\r\n";
respond += "Content-Length: " + f.length() + "\r\n";
respond += "Connection: keep-alive\r\n";
respond += "\r\n";
output.write((respond).getBytes());
output.flush();
ImageIO.write(bi,"JPG",output);
output.flush();

我在浏览器中进行了测试,它工作正常,但是当我从 android 调用 Glide 时,没有显示图像

最佳答案

Content-Length 可能会混淆 glide,因为你在撒谎,原始文件长度可能与重新编码的 JPG 输出不同。

您还在 Content-Type 方面撒了谎,因为它是 JPG,而不是您所说的 PNG,但我认为 Glide 会忽略这一点。

我认为最好将imageLocation的字节发送到output,然后可以预测Content-Length简单地说。

i still trying to figure how to get any exception from Glide if exist

Google Groups discussion 中所述,阅读https://github.com/bumptech/glide/wiki/Debugging-and-Error-Handling我建议您在 .into(imageView) 之前添加 .listener(new RequestListener...) 并记录参数以查看发生了什么。

关于java - 如何创建一个从 Glide 请求图像发送图像的服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32304672/

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