Hi everyone,
I’‘m a little frustrated at the moment, I’'m just trying to save the avatar from a contact into a file.
The problem is that image is always “null” after image = ImageIO.read(new ByteArrayInputStream(avatar)); … but why ?
I used several contacts and images but every time I get the same problem.
Maybe somebody can tell me what I have to do :).
Sample Code:
public void getAvatar () {
System.out.println (“Fetching avatar”);
BufferedImage image = null;
VCard vCard = new VCard ();
try {
vCard.load (this.xmppCon, "875-1@s1.openmessenger.de");
byte[] avatar = vCard.getAvatar();
image = ImageIO.read(new ByteArrayInputStream(avatar));
if (image != null) {
Graphics2D g2 = image.createGraphics();
g2.drawImage(image, 0, 0, null);
g2.dispose();
ImageIO.write(image, “jpg”, new File(“imageTest.jpg”));
System.out.println (“Should be saved”);
} else
System.out.println (“NARF!”);
} catch (XMPPException e) {
e.printStackTrace();
} catch (IOException e) {
System.out.println (“args”);
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace ();
}
}