简体   繁体   English

我们如何显示来自Picasa Java API的照片?

[英]How do we display a photo from Picasa java API?

Okay, it seems to be a stupid question, since we have this 好了,这似乎是一个愚蠢的问题,因为我们有这个

However, up to the moment, I can only succeed in displaying the thumbnails by using: 但是,到目前为止,我只能使用以下方法成功显示缩略图:

PhotoEntry photo = //somehow I get the instance
photo.getMediaThumbnails().get(0).getUrl()

The biggest photo I can display through this method is up to 300 pixel or so[which is photo.getMediaThumbnails().get(3) ]. 我可以通过此方法显示的最大照片最多为300像素左右(即photo.getMediaThumbnails().get(3) )。 How can I display the a thumbnail up to 400 pixel or even 800 pixel? 如何显示最大400像素甚至800像素的缩略图? Or How can I even refer back to the google picasa page that can actually help me display this photo? 或什至我该如何返回Google Picasa页面,实际上可以帮助我显示这张照片?

Thanks 谢谢

Quite Simple 非常简单

 PhotoEntry photo = //somehow I get the instance
    photo.getMediaThumbnails().get(0).getUrl()

You can use this way to get that 400/800px photo. 您可以使用这种方式来获取400 / 800px的照片。

You only have to change the result URL that is given. 您只需要更改给出的结果URL。 Change the s144/s400/s800 value of the URL 更改URL的s144 / s400 / s800值

BLAH com/_BwderBVv7wg/XXXXXXXXX/AAAAAAAAAME/HdXja0HclK0/s72/DSC09176.JPG
BLAH com/_BwderBVv7wg/XXXXXXXXX/AAAAAAAAAME/HdXja0HclK0/s144/DSC09176.JPG
BLAH com/_BwderBVv7wg/XXXXXXXXX/AAAAAAAAAME/HdXja0HclK0/s288/DSC09176.JPG
BLAH com/_BwderBVv7wg/XXXXXXXXX/AAAAAAAAAME/HdXja0HclK0/s400/DSC09176.JPG
BLAH com/_BwderBVv7wg/XXXXXXXXX/AAAAAAAAAME/HdXja0HclK0/s800/DSC09176.JPG

The following was answered by a community member of google picasa api: google picasa api的社区成员回答了以下问题:

Take a look at 看一眼

http://code.google.com/apis/picasaweb/docs/2.0/reference.html#Parameters http://code.google.com/apis/picasaweb/docs/2.0/reference.html#Parameters

It explains how you can control the size of the image that the media:content link points to as well as how you can request different thumbsizes for the media:thumbnail links. 它说明了如何控制media:content链接指向的图像的大小,以及如何为media:thumbnail链接请求不同的缩略图大小。 Also listed are the valid size values available. 还列出了可用的有效尺寸值。 Note though, that you can only access images up to 800px in size (width or height, whatever is larger) from websites. 不过请注意,您只能从网站访问大小最大为800px(宽度或高度,较大的)的图像。

For instance: 例如:

GET /feed/api/user//albumid/? GET / feed / api / user // albumid /? kind=photo&imgmax=800&thumbsize=512,400,160c kind = photo&imgmax = 800&thumbsize = 512,400,160c

will give you a link to an 800px version in the media:content link, a link to the uncropped 512px and 400px version in the first two media:thumbnail elements and a square-cropped 160x160 thumbnail in the third thumbnail element. 将为您提供一个指向media:content链接中800px版本的链接,一个指向前两个media:thumbnail元素中未裁剪的512px和400px版本的链接,以及第三个缩略图元素中的正方形裁剪的160x160缩略图的链接。

Cheers, Detlev 干杯,Detlev

If you are using Picasa Java API and need to get image URL after uploading try to use following code 如果您使用的是Picasa Java API,并且需要在上传后获取图片网址,请尝试使用以下代码

    try {
        File photoFile = new File(getFileName());
        service = new PicasawebService(applicationName);
        MediaFileSource photoMedia = new MediaFileSource(photoFile, "image/jpg");
        URL albumPostUrl = new URL(String.format("http://picasaweb.google.com/data/feed/api/user/%1$s/albumid/%2$s", getUserName(), getAlbumId()));
        PhotoEntry returnedPhoto = service.insert(albumPostUrl, PhotoEntry.class, photoMedia);

        String href = returnedPhoto.getHtmlLink().getHref();

        if (returnedPhoto.getMediaContents().size() > 0) {
            // !!!!!!!!!!!!!!!This is exactly JPEG URL
            href = returnedPhoto.getMediaContents().get(0).getUrl();
        }
        logger.info(String.format("Image published: <%s>", href));
        return href;
    } catch (AuthenticationException e) {
        logger.error(e.getMessage(), e);
        e.printStackTrace();
    } catch (MalformedURLException e) {
        logger.error(e.getMessage(), e);
        e.printStackTrace();
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        e.printStackTrace();
    } catch (ServiceException e) {
        logger.error(e.getMessage(), e);
        e.printStackTrace();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM