gpt4 book ai didi

android - 将 Facebook ProfilePictureView 转换为位图以在 ImageView 中使用

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

我正在尝试转换从 Facebook 返回的个人资料图像并将其更改为位图,以便我可以在需要位图的方法中使用它。我可以使用下面的代码获取个人资料图片并将其放入 ProfilePictureView。我还创建了另外两个用于测试的 View ...一个 CircleImageView 和一个 ImageView。到目前为止,只有 ProfilePictureView 显示图像。这是我尝试过的代码示例,尽管我已经尝试了几种在网上找到的创建位图的方法,但都没有奏效。任何建议/解决方案将不胜感激!

    ProfilePictureView profilePictureView;
profilePictureView = (ProfilePictureView) findViewById(R.id.facebookPictureView);
profilePictureView.setProfileId(userId); //this works to get and set the profile pic

standardImageView = (ImageView) findViewById(R.id.imageView);
circleImageView = (CircleImageView) findViewById(R.id.profImage);

AsyncTask<Void, Void, Bitmap> t = new AsyncTask<Void, Void, Bitmap>() {
protected Bitmap doInBackground(Void... p) {
Bitmap bmp = null;
try {
URL aURL = new URL("http://graph.facebook.com/" + userId + "/picture?type=large");
URLConnection conn = aURL.openConnection();
conn.setUseCaches(true);
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bmp = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return bmp;
}

protected void onPostExecute(Bitmap bmp) {

standardImageView.setImageBitmap(bmp);
circleImageView.setImageBitmap(bmp);
}
};
t.execute();

使用调试器并单步执行,我发现 bmp 为空。我尝试了其他几种方法,同样的事情也发生了。帮助!

最佳答案

您也可以决定使用 Glide,这是 Picasso 的更好选择

Bitmap theBitmap = null;
theBitmap = Glide.
with(getActivigetApplicationContext()).
load("your image url here").
asBitmap().
into(-1, -1).
get();

关于android - 将 Facebook ProfilePictureView 转换为位图以在 ImageView 中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32857367/

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