如何获得高品质的图像头像smack xmpp facebook

时间:2014-12-24 05:43:39

标签: facebook xmpp smack vcard

我使用Vcard smack获取头像图片,但它返回给我图片头像尺寸32 * 32

小图像所以我想获得高质量,如facebook do或其他app做

有人能帮助我吗?

我尝试在gooogle中搜索,但几乎所有线程都说使用Vcard获取头像

我使用以下方法获取Vcard的头像<​​/ p>

=&GT;我的解决方案是使用facebook的图形api:

String urlAvatar = "https://graph.facebook.com/" + StringUtils.parseName(childrenEntryItems.getJid()).
replace("-", "") + "/picture?type=normal";

public static byte[] getAvatarByteArray(XMPPConnection xmppConnection, String user) {
		VCard vCard = new VCard();
		SmackConfiguration.setPacketReplyTimeout(30000);
//		ProviderManager.getInstance().addIQProvider("vCard", "vcard-temp",
//				new VCardProvider());
		try {
			vCard.load(xmppConnection, user);
		} catch (XMPPException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
//		Log.d("Giang", vCard.toXML() + " byte length = "
//				+ vCard.getAvatar().length); // complete VCard information

		return vCard.getAvatar();
	}
	
	public static Bitmap makeBitemap(byte[] value) {
		if (value == null)
			return null;

		// Load only size values
		BitmapFactory.Options sizeOptions = new BitmapFactory.Options();
		sizeOptions.inJustDecodeBounds = true;
		BitmapFactory.decodeByteArray(value, 0, value.length, sizeOptions);

		// Calculate factor to down scale image
		int scale = 1;
		int width_tmp = sizeOptions.outWidth;
		int height_tmp = sizeOptions.outHeight;
		while (width_tmp / 2 >= 256 && height_tmp / 2 >= 256) {
			scale *= 2;
			width_tmp /= 2;
			height_tmp /= 2;
		}

		// Load image
		BitmapFactory.Options resultOptions = new BitmapFactory.Options();
		resultOptions.inSampleSize = scale;
		return BitmapFactory.decodeByteArray(value, 0, value.length,
				resultOptions);
	}

1 个答案:

答案 0 :(得分:0)

我认为最好的协议是将头像的url存储在一个自定义v-cards中,并使用一些图像加载库通过HTTP获取它。请记住,xmpp是基于流的体系结构,我会谨慎地通过发送大文件来阻止流。