简体   繁体   English

在ICS上的缩略图中选择Picasa图片并选择图片

[英]Thumbnails and picking picasa images from gallery on ICS

I'm having a hard time getting Thumbnails.getThumbnail to work with picasa photos on a Nexus S running ICS. 我很难让Thumbnails.getThumbnail在运行ICS的Nexus S上处理picasa照片。 Everything else seems to work including getting the original image from picasa and displaying it, but the getThumbnail doesn't seem to work. 其他一切似乎都可行,包括从picasa中获取原始图像并进行显示,但getThumbnail似乎不起作用。 I'm getting the following errors when attempting to use it: 尝试使用它时出现以下错误:

E/MiniThumbFile( 1852): Got exception when reading magic, id = 5745625138093120418, disk full or mount read-only? class java.lang.IllegalArgumentException
W/MediaProvider(  540): original media doesn't exist or it's canceled.

The disk is not full, it is read-write, the app has external storage write permissions, and the picture does indeed exist on picasa (I can view it through the android Gallery app). 磁盘未满,它是可读写的,该应用程序具有外部存储写入权限,并且图片确实存在于picasa中(我可以通过android Gallery应用程序查看它)。

The same code works fine on Android 2.3, but it follows a slightly different path, as 2.3 seems to download a copy of the photo and hand you the actual local file:// uri to the newly downloaded image, rather than hand you a content:// uri. 相同的代码在Android 2.3上可以正常工作,但它采用的路径略有不同,因为2.3似乎下载了照片副本,并将实际的本地文件:// uri交给了新下载的图像,而不是为您提供了内容// uri。

This is the main meat of the code in question: 这是相关代码的主要内容:

  public void addImage(Uri uri, boolean local)
  {
     ContentResolver resolver = getContentResolver();
     Uri actualUri = uri;

     Log.d(TAG, "addImage: original uri: " + uri.toString());

     if(local) {
        try {
           List<String> uriPath = uri.getPathSegments();
           String contentUri = Media.insertImage(resolver, uri.getPath(), uriPath.get(uriPath.size()-1), new String());
           actualUri = Uri.parse(contentUri);
        }
        catch(java.io.FileNotFoundException ex) {
           Log.e(TAG, "FileNotFoundException: ");
           ex.printStackTrace();
        }
     }

     Log.d(TAG, "addImage: actual uri: " + actualUri.toString());

     List<String> uriPath = actualUri.getPathSegments();
     long imageId = Long.parseLong(uriPath.get(uriPath.size() -1));

     Bitmap thumb = Thumbnails.getThumbnail(resolver, imageId, Thumbnails.MINI_KIND, null);
     if(thumb == null) {
        Log.e(TAG, "Failed to get thumbnail for our image.");
        Toast toast = Toast.makeText(getApplicationContext(), "Failed to get thumbnail for image. Please try again.", Toast.LENGTH_SHORT);
        toast.show();
        return;
     }

     uris.add(uri);
     bmps.add(thumb);
     notifyDataSetChanged();
  }

That method is called when ever a new photo is added to the application's "collection" of photos. 每当将新照片添加到应用程序的照片“集合”时,都会调用该方法。 When its known to be a local image (ie: if a photo was taken from inside the app, or onActivityResult's data argument is null), the local parameter is set to true and I attempt to get a content:// uri back from the media content provider so we can get a valid image id to pass to Thumbnails.getThumbnail. 如果已知它是本地图像(即:如果照片是从应用程序内部拍摄的,或者onActivityResult的data参数为null),则将local参数设置为true,然后尝试从中获取content:// uri媒体内容提供者,因此我们可以获得有效的图像ID,以传递给Thumbnails.getThumbnail。 That code works fine for images gotten from the Camera app (via startActivityForResult), as well as images from the gallery that are stored locally on the device. 该代码对于从“相机”应用程序(通过startActivityForResult)获取的图像以及库中本地存储在设备上的图像均适用。

I'm a bit stumped. 我有点难过。

https://developers.google.com/picasa-web/docs/2.0/reference#media_group https://developers.google.com/picasa-web/docs/2.0/reference#media_group

If you are having a hard time in android getting to the thumbnails, note the above link and api and the media:group/media:thumbnail tag in the atom feed. 如果您在使用android时遇到麻烦,请注意上面的链接和api,以及原子供稿中的media:group / media:thumbnail标签。 Thats the parent element or the container of the thumbnails refered to in this post 多数民众赞成在父元素或在这篇文章中引用的缩略图的容器

So, in order to process thumbs in android, if you can structure your code to actually use the api ( picasa feeds / photos / media:group etc. ) you may have fewer bugs issues like the present one. 因此,为了在android中处理拇指,如果您可以构造代码以实际使用api(picasa feeds / photos / media:group等),则可能会出现像当前这样的bug问题。

Sample google/ android / picasa code 示例Google / Android / Picasa 代码

api ref API参考

another api ref 另一个API参考

Had the same problem and it was an import/package problem. 遇到相同的问题,这是导入/打包问题。

Make sure to use the correct Thumbnail class. 确保使用正确的Thumbnail类。 There are two. 那里有两个。 One for Video and one for Images. 一个用于视频,另一个用于图像。

MediaStore.Images.Thumbnails
MediaStore.Video.Thumbnails

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

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