|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectezvcard.property.VCardProperty
ezvcard.property.BinaryProperty<ImageType>
ezvcard.property.ImageProperty
ezvcard.property.Photo
public class Photo
A photo attached to the vCard (such as a portrait of the person).
Adding a photo
VCard vcard = new VCard();
//URL
Photo photo = new Photo("http://www.mywebsite.com/mugshot.jpg", ImageType.JPEG);
vcard.addPhoto(photo);
//binary data
byte data[] = ...
photo = new Photo(data, ImageType.JPEG);
vcard.addPhoto(photo);
//if "ImageType" does not have the pre-defined constant that you need, then create a new instance
//arg 1: the value of the 2.1/3.0 TYPE parameter
//arg 2: the value to use for the 4.0 MEDIATYPE parameter and for 4.0 data URIs
//arg 3: the file extension of the data type (optional)
ImageKeyTypeParameter param = new ImageType("bmp", "image/x-ms-bmp", "bmp");
photo = new Photo("http://www.mywebsite.com/mugshot.bmp", param);
vcard.addPhoto(photo);
Getting the photos
VCard vcard = ...
int fileCount = 0;
for (Photo photo : vcard.getPhotos()){
//the photo will have either a URL or a binary data
if (photo.getData() == null){
System.out.println("Photo URL: " + photo.getUrl());
} else {
ImageType type = photo.getContentType();
if (type == null) {
//the vCard may not have any content type data associated with the photo
System.out.println("Saving a photo file...");
} else {
System.out.println("Saving a \"" + type.getMediaType() + "\" file...");
}
String folder;
if (type == ImageType.JPEG){ //it is safe to use "==" instead of "equals()"
folder = "photos";
} else {
folder = "images";
}
byte data[] = photo.getData();
String filename = "photo" + fileCount;
if (type != null && type.getExtension() != null){
filename += "." + type.getExtension();
}
OutputStream out = new FileOutputStream(new File(folder, filename));
out.write(data);
out.close();
fileCount++;
}
}
Property name: PHOTO
Supported versions: 2.1, 3.0, 4.0
| Field Summary |
|---|
| Fields inherited from class ezvcard.property.BinaryProperty |
|---|
contentType, data, url |
| Fields inherited from class ezvcard.property.VCardProperty |
|---|
group, parameters |
| Constructor Summary | |
|---|---|
Photo(byte[] data,
ImageType type)
Creates a photo property. |
|
Photo(File file,
ImageType type)
Creates a photo property. |
|
Photo(InputStream in,
ImageType type)
Creates a photo property. |
|
Photo(String url,
ImageType type)
Creates a photo property. |
|
| Method Summary |
|---|
| Methods inherited from class ezvcard.property.BinaryProperty |
|---|
_validate, addPid, getAltId, getContentType, getData, getPids, getPref, getType, getUrl, removePids, setAltId, setContentType, setData, setPref, setType, setUrl |
| Methods inherited from class ezvcard.property.VCardProperty |
|---|
_supportedVersions, addParameter, compareTo, getGroup, getParameter, getParameters, getParameters, getSupportedVersions, removeParameter, setGroup, setParameter, setParameters, validate |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Photo(String url,
ImageType type)
url - the URL to the phototype - the content type (e.g. JPEG)
public Photo(byte[] data,
ImageType type)
data - the binary data of the phototype - the content type (e.g. JPEG)
public Photo(InputStream in,
ImageType type)
throws IOException
in - an input stream to the binary data (will be closed)type - the content type (e.g. JPEG)
IOException - if there's a problem reading from the input stream
public Photo(File file,
ImageType type)
throws IOException
file - the image filetype - the content type (e.g. JPEG)
IOException - if there's a problem reading from the file
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||