gpt4 book ai didi

android - 无法从谷歌个人资料图片网址获取位图

转载 作者:搜寻专家 更新时间:2023-11-01 08:27:37 28 4
gpt4 key购买 nike

我有一个应用程序,我试图从通过谷歌集成获得的链接中检索图像。但是,每当我尝试将图片转换为位图时,它总是给我一个错误。代码和错误如下:

代码:

if (google_user_gallery_pic.isEmpty() == true)
{
if (google_user_pic.isEmpty() == false)
{
onPost = null;
onPost2 = null;
onPost = getBitmapFromURL(google_user_pic);
onPost2 = onPost2.createScaledBitmap(onPost, 100, 100, false);
}

else
{
onPost = null;
onPost2 = null;
onPost = BitmapFactory.decodeFile(google_user_gallery_pic);
if (onPost == null)
{
onPost2 = BitmapFactory.decodeResource(getResources(), R.drawable.the_smallperson);
}

else
{
onPost2 = onPost2.createScaledBitmap(onPost, 100, 100, false);
}
}
}

else
{
onPost = null;
onPost2 = null;
onPost = BitmapFactory.decodeFile(google_user_gallery_pic);
if (onPost == null)
{
onPost2 = BitmapFactory.decodeResource(getResources(), R.drawable.the_smallperson);
//onPost2 = onPost2.createScaledBitmap(onPost, 100, 100, false);
}

else
{
onPost2 = onPost2.createScaledBitmap(onPost, 100, 100, false);
}
}

错误:

E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: https:/lh3.googleusercontent.com/-HW5Tk9h1V2I/AAAAAAAAAAI/AAAAAAAADA8/7UbMeHbyFLM/photo.jpg: open failed: ENOENT (No such file or directory)

网址:

https://lh3.googleusercontent.com/-HW5Tk9h1V2I/AAAAAAAAAAI/AAAAAAAADA8/7UbMeHbyFLM/photo.jpg

此 url 在一个页面上有效,但在另一个页面上无效。这两个页面都是 fragment Activity 。任何帮助将不胜感激,谢谢!

最佳答案

尝试将 if 和 else 条件反转为如下所示:

if (google_user_gallery_pic.isEmpty() == false)
{
if (google_user_pic.isEmpty() == false)
{
onPost = null;
onPost2 = null;
onPost = getBitmapFromURL(google_user_pic);
onPost2 = onPost2.createScaledBitmap(onPost, 100, 100, false);
}

else
{
onPost = null;
onPost2 = null;
onPost = BitmapFactory.decodeFile(google_user_gallery_pic);
if (onPost == null)
{
onPost2 = BitmapFactory.decodeResource(getResources(), R.drawable.the_smallperson);
}

else
{
onPost2 = onPost2.createScaledBitmap(onPost, 100, 100, false);
}
}
}

else
{
onPost = null;
onPost2 = null;
onPost = BitmapFactory.decodeFile(google_user_gallery_pic);
if (onPost == null)
{
onPost2 = BitmapFactory.decodeResource(getResources(), R.drawable.the_smallperson);
//onPost2 = onPost2.createScaledBitmap(onPost, 100, 100, false);
}

else
{
onPost2 = onPost2.createScaledBitmap(onPost, 100, 100, false);
}
}

因为给定了权限和其他任何东西而不是这个代码 fragment ,所以除此之外没有任何问题

关于android - 无法从谷歌个人资料图片网址获取位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43296252/

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