尝试在UI上显示来自自动下载链接的图片时出现问题。毕加索和格莱德不知道如何打开它。他们正在寻找一个地址。
例如,我有这张照片https://graph.facebook.com/10155174010491889/picture?type=large。当您访问该链接时,您将自动获得下载的图片。毕加索并不知道如何处理这个问题。
我研究了这个问题(https://github.com/square/picasso/issues/463),应用了OkHttpClient和下载程序,但它仍然无法运行:
OkHttpClient client = new OkHttpClient.Builder().build();
Downloader downloader = new OkHttp3Downloader(client);
new Picasso.Builder(context)
.downloader(downloader)
.listener((picasso, uri, exception) -> {
exception.printStackTrace();
Log.d(TAG, "loadImageWithPicasso: " + exception);
})
.build()
.load(Uri.parse(path))
.centerCrop()
.fit()
.into(imageView, new Callback() {
@Override
public void onSuccess() {
imageView.setImageDrawable(ImageUtils.roundedCornersImage(context, imageView));
}
@Override
public void onError() {
imageView.setImageResource(resourceDrawable);
}
});
我甚至单独尝试对该图像发出OkHTTP请求并获得奇怪的结果 - 位图null(当尝试下载为位图时),网络响应重定向url图像的大小为0(https://m.facebook.com/platform/profilepic/?asid=10155174010491889&height=200&width=200)
getRequest("https://graph.facebook.com/10155174010491889/picture?type=large", new okhttp3.Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
Log.d(TAG, "body = " + response.body());
Log.d(TAG, "network response = " + response.networkResponse().toString());
InputStream inputStream = response.body().byteStream();
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
Log.d(TAG, response.networkResponse().request().url() + " <<<<");
}
@Override
public void onFailure(Call call, IOException e) {
}
});
}
}
public static void getRequest(String url, okhttp3.Callback callback) {
OkHttpClient client = new OkHttpClient.Builder().build();
Request request = new Request.Builder()
.url(url)
.get()
.build();
client.newCall(request).enqueue(callback);
}
我看到Postman用简单的GET打开图片,没有任何隐含的问题。
你有什么建议我作为这种情况的解决方案?
答案 0 :(得分:1)
Glide.with(context)
.load("https://graph.facebook.com/10155174010491889/picture?type=large")
.centerCrop().listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e,
String model,
Target<GlideDrawable> target,
boolean isFirstResource) {
spinKitView.setVisibility(View.GONE);
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource,
String model,
Target<GlideDrawable> target,
boolean isFromMemoryCache, boolean isFirstResource) {
spinKitView.setVisibility(View.GONE);
return false;
}
}).into(profile_picture);
答案 1 :(得分:1)
您的链接在 Glide 4.6.1
中完美运行Glide.with(this)
.load("https://graph.facebook.com/10155174010491889/picture?type=large")
.into(imageview);