本文整理汇总了Java中com.flickr4java.flickr.photos.PhotosInterface类的典型用法代码示例。如果您正苦于以下问题:Java PhotosInterface类的具体用法?Java PhotosInterface怎么用?Java PhotosInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PhotosInterface类属于com.flickr4java.flickr.photos包,在下文中一共展示了PhotosInterface类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBy
import com.flickr4java.flickr.photos.PhotosInterface; //导入依赖的package包/类
private BufferedImage getBy(IndexData indexData) {
try {
PhotosInterface photosInterface = flickrFactory.getFlickr().getPhotosInterface();
Photo photo = photosInterface.getPhoto(indexData.getId().getPictureId());
return photosInterface.getImage(photo, Size.SQUARE);
} catch (FlickrException e) {
throw new RuntimeException(e);
}
}
示例2: FindPicture
import com.flickr4java.flickr.photos.PhotosInterface; //导入依赖的package包/类
public FindPicture() {
try {
String apikey = "Your API key";
String secret = "Your secret";
Flickr flickr = new Flickr(apikey, secret, new REST());
SearchParameters searchParameters = new SearchParameters();
searchParameters.setBBox("-180", "-90", "180", "90");
searchParameters.setMedia("photos");
PhotoList<Photo> list = flickr.getPhotosInterface().search(searchParameters, 10, 0);
out.println("Image List");
for (int i = 0; i < list.size(); i++) {
Photo photo = list.get(i);
out.println("Image: " + i
+ "\nTitle: " + photo.getTitle()
+ "\nMedia: " + photo.getOriginalFormat()
+ "\nPublic: " + photo.isPublicFlag()
+ "\nPublic: " + photo.isPublicFlag()
+ "\nUrl: " + photo.getUrl()
+ "\n");
}
out.println();
PhotosInterface pi = new PhotosInterface(apikey, secret, new REST());
out.println("pi: " + pi);
Photo currentPhoto = list.get(0);
out.println("currentPhoto url: " + currentPhoto.getUrl());
// Get image using URL
BufferedImage bufferedImage = pi.getImage(currentPhoto.getUrl());
out.println("bi: " + bufferedImage);
// Get image using Photo instance
bufferedImage = pi.getImage(currentPhoto, Size.SMALL);
// Save image to file
out.println("bufferedImage: " + bufferedImage);
File outputfile = new File("image.jpg");
ImageIO.write(bufferedImage, "jpg", outputfile);
} catch (FlickrException | IOException ex) {
ex.printStackTrace();
}
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:46,代码来源:FindPicture.java
示例3: searchOnParams
import com.flickr4java.flickr.photos.PhotosInterface; //导入依赖的package包/类
/**
* the expanded class FlickrSearchParameters is queried to determine what
* fine-tuning of the search parameters is required before submitting to the
* flickr service API. If a tag search has been requested, the tags will be
* tokenised on commas if any are present, otherwise on spaces. If a value
* has been set for a flickr user string, that string is examined to see if
* it is an email, a flick user-id or (failing either) a flickr user-name.
*/
@Override
public PhotoList<Photo> searchOnParams(FlickrSearchParameters params, int pageToGet, int queryLimit,
String apiKey,
String apiSharedSecret) throws FlickrException
{
Flickr flickr = getFlickr(apiKey, apiSharedSecret);
// From the unparsed user input, see if there's either a flick userid
// already provided; otherwise get the flickr id by specialised flickr
// query
/* boolean sendingFlickrUserId = */
extractUserSearchString(flickr, params);
if( params.getSearchRawText() != null )
{
String rawText = params.getSearchRawText().trim();
if( rawText.length() > 0 )
{
if( params.isTagsNotText() )
{
if( rawText.contains(",") )
{
params.setTags(rawText.split(","));
}
else
{
params.setTags(rawText.split(" "));
}
if( params.isTagsAll() )
{
params.setTagMode(ALL);
}
else
{
params.setTagMode(ANY);
}
}
else
{
params.setText(rawText);
}
}
}
// The various extras flags (to specify level of detail retrieved)
params.setExtras(EXTRAS_SET);
PhotosInterface photosInterface = flickr.getPhotosInterface();
try
{
PhotoList<Photo> photoList = photosInterface.search(params, queryLimit, pageToGet);
return photoList;
}
catch( FlickrException fe ) // NOSONAR
{
throw fe;
}
catch( Exception e )
{
throw Throwables.propagate(e);
}
}
示例4: run
import com.flickr4java.flickr.photos.PhotosInterface; //导入依赖的package包/类
@Override
public void run() {
this.statusLabel.setText("Initializing download process...");
progressBar.setValue(0);
File directory = this.getBackupDirectory();
if (!directory.mkdirs()) {
}
PeopleInterface peopleInt = flickr.getPeopleInterface();
PhotosInterface photoInt = flickr.getPhotosInterface();
int pages = 1;
int page = 1;
int total = 0;
int current = 0;
int error = 0;
Set<String> options = new HashSet<>();
options.add("original_format");
Integer size = Size.ORIGINAL;
try {
do {
RequestContext.getRequestContext().setAuth(this.getAuth());
PhotoList<Photo> list = peopleInt.getPhotos("me", null, null, null, null, null, null, null, options, 500, page);
if (page == 1) {
pages = list.getPages();
total = list.getTotal();
progressBar.setMinimum(0);
progressBar.setMaximum(total);
progressBar.setValue(0);
}
Iterator<Photo> it = list.iterator();
while (it.hasNext() && isRunning) {
current++;
Photo p = it.next();
this.statusLabel.setText("Photo " + current + " of " + total + ": Downloading");
try {
File newFile = new File(directory, this.generateFilename(p, size));
if (!newFile.exists()) {
BufferedInputStream bis = new BufferedInputStream(photoInt.getImageAsStream(p, size));
FileOutputStream fos = new FileOutputStream(newFile);
int read;
byte[] buffer = new byte[100 * 1024];
while ((read = bis.read(buffer)) != -1) {
fos.write(buffer, 0, read);
}
fos.flush();
fos.close();
bis.close();
}
} catch (Exception e) {
error++;
}
progressBar.setValue(current);
}
page++;
} while (page <= pages && isRunning);
statusLabel.setText(isRunning ? "Download of " + total + " photos finished. " + (error == 0 ? "No" : error) + " errors occured!" : "Stopped downloading process. You can resume it at any time.");
} catch (FlickrException ex) {
statusLabel.setText(ex.getMessage());
}
isRunning = false;
updateComponents();
}
示例5: getImage
import com.flickr4java.flickr.photos.PhotosInterface; //导入依赖的package包/类
private BufferedImage getImage(String pictureId) throws FlickrException {
final PhotosInterface photosInterface = flickrFactory.getFlickr().getPhotosInterface();
Photo photo = photosInterface.getPhoto(pictureId);
return photosInterface.getImage(photo, Size.SQUARE);
}
示例6: retrieveAccountFeed
import com.flickr4java.flickr.photos.PhotosInterface; //导入依赖的package包/类
@Override
public Response retrieveAccountFeed(AccountFeed feed, Integer maxRequests) {
Response response = new Response();
List<Post> items = new ArrayList<Post>();
Date dateToRetrieve = feed.getSinceDate();
String label = feed.getLabel();
int page=1, pages=1; //pagination
int numberOfRequests = 0;
//Here we search the user by the userId given (NSID) -
// however we can get NSID via flickrAPI given user's username
String userID = feed.getId();
if(userID == null) {
logger.info("#Flickr : No source feed");
return response;
}
PhotosInterface photosInteface = flickr.getPhotosInterface();
SearchParameters params = new SearchParameters();
params.setUserId(userID);
params.setMinUploadDate(dateToRetrieve);
Set<String> extras = new HashSet<String>(Extras.ALL_EXTRAS);
extras.remove(Extras.MACHINE_TAGS);
params.setExtras(extras);
while(page<=pages && numberOfRequests<=maxRequests) {
PhotoList<Photo> photos;
try {
numberOfRequests++;
photos = photosInteface.search(params , PER_PAGE, page++);
} catch (Exception e) {
break;
}
pages = photos.getPages();
if(photos.isEmpty()) {
break;
}
for(Photo photo : photos) {
String userid = photo.getOwner().getId();
UserAccount streamUser = userMap.get(userid);
if(streamUser == null) {
streamUser = getStreamUser(userid);
userMap.put(userid, streamUser);
}
FlickrPost flickrItem = new FlickrPost(photo);
flickrItem.setLabel(label);
items.add(flickrItem);
}
}
response.setPosts(items);
response.setRequests(numberOfRequests);
return response;
}
示例7: retrieveUserFeeds
import com.flickr4java.flickr.photos.PhotosInterface; //导入依赖的package包/类
@Override
public List<Item> retrieveUserFeeds(SourceFeed feed) {
List<Item> items = new ArrayList<Item>();
long currRunningTime = System.currentTimeMillis();
Date dateToRetrieve = feed.getDateToRetrieve();
String label = feed.getLabel();
int page=1, pages=1; //pagination
int numberOfRequests = 0;
int numberOfResults = 0;
//Here we search the user by the userId given (NSID) -
// however we can get NSID via flickrAPI given user's username
Source source = feed.getSource();
String userID = source.getId();
if(userID == null) {
logger.info("#Flickr : No source feed");
return items;
}
PhotosInterface photosInteface = flickr.getPhotosInterface();
SearchParameters params = new SearchParameters();
params.setUserId(userID);
params.setMinUploadDate(dateToRetrieve);
Set<String> extras = new HashSet<String>(Extras.ALL_EXTRAS);
extras.remove(Extras.MACHINE_TAGS);
params.setExtras(extras);
while(page<=pages && numberOfRequests<=maxRequests && numberOfResults<=maxResults &&
(System.currentTimeMillis()-currRunningTime)<maxRunningTime) {
PhotoList<Photo> photos;
try {
numberOfRequests++;
photos = photosInteface.search(params , PER_PAGE, page++);
} catch (Exception e) {
break;
}
pages = photos.getPages();
numberOfResults += photos.size();
if(photos.isEmpty()) {
break;
}
for(Photo photo : photos) {
String userid = photo.getOwner().getId();
StreamUser streamUser = userMap.get(userid);
if(streamUser == null) {
streamUser = getStreamUser(userid);
userMap.put(userid, streamUser);
}
FlickrItem flickrItem = new FlickrItem(photo, streamUser);
flickrItem.setList(label);
items.add(flickrItem);
}
}
//logger.info("#Flickr : Done retrieving for this session");
// logger.info("#Flickr : Handler fetched " + items.size() + " photos from " + userID +
// " [ " + lastItemDate + " - " + new Date(System.currentTimeMillis()) + " ]");
// The next request will retrieve only items of the last day
dateToRetrieve = new Date(System.currentTimeMillis() - (24*3600*1000));
feed.setDateToRetrieve(dateToRetrieve);
return items;
}
示例8: retrieveLocationFeeds
import com.flickr4java.flickr.photos.PhotosInterface; //导入依赖的package包/类
@Override
public List<Item> retrieveLocationFeeds(LocationFeed feed){
List<Item> items = new ArrayList<Item>();
long currRunningTime = System.currentTimeMillis();
Date dateToRetrieve = feed.getDateToRetrieve();
String label = feed.getLabel();
Double[][] bbox = feed.getLocation().getbbox();
if(bbox == null || bbox.length==0)
return items;
int page=1, pages=1;
int numberOfRequests = 0;
int numberOfResults = 0;
PhotosInterface photosInteface = flickr.getPhotosInterface();
SearchParameters params = new SearchParameters();
params.setBBox(bbox[0][0].toString(), bbox[0][1].toString(), bbox[1][0].toString(), bbox[1][1].toString());
params.setMinUploadDate(dateToRetrieve);
Set<String> extras = new HashSet<String>(Extras.ALL_EXTRAS);
extras.remove(Extras.MACHINE_TAGS);
params.setExtras(extras);
while(page<=pages && numberOfRequests<=maxRequests && numberOfResults<=maxResults &&
(System.currentTimeMillis()-currRunningTime)<maxRunningTime) {
PhotoList<Photo> photos;
try {
photos = photosInteface.search(params , PER_PAGE, page++);
} catch (FlickrException e) {
break;
}
pages = photos.getPages();
numberOfResults += photos.size();
if(photos.isEmpty()) {
break;
}
for(Photo photo : photos) {
String userid = photo.getOwner().getId();
StreamUser streamUser = userMap.get(userid);
if(streamUser == null) {
streamUser = getStreamUser(userid);
userMap.put(userid, streamUser);
}
FlickrItem flickrItem = new FlickrItem(photo, streamUser);
flickrItem.setList(label);
items.add(flickrItem);
}
}
logger.info("#Flickr : Handler fetched " + items.size() + " photos "+
" [ " + dateToRetrieve + " - " + new Date(System.currentTimeMillis()) + " ]");
return items;
}