缩略图并从ICS上的图库中选取picasa图像

时间:2012-05-25 00:47:44

标签: android thumbnails android-4.0-ice-cream-sandwich picasa

我很难在运行ICS的Nexus S上使用Thumbnails.getThumbnail来处理picasa照片。其他一切似乎都有效,包括从picasa获取原始图像并显示它,但getThumbnail似乎不起作用。我在尝试使用它时遇到以下错误:

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.

磁盘未满,它是读写,应用程序具有外部存储写入权限,图片确实存在于picasa上(我可以通过android Gallery应用程序查看)。

相同的代码在Android 2.3上工作正常,但它遵循一个稍微不同的路径,因为2.3似乎下载了照片的副本并将实际的本地文件:// uri交给新下载的图像,而不是手你有一个内容:// uri。

这是相关代码的主要内容:

  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();
  }

当将新照片添加到应用程序的“照片集”时,会调用该方法。当已知它是本地图像时(即:如果照片是从应用程序内部拍摄的,或者onActivityResult的数据参数为null),则将local参数设置为true并尝试从内容中获取内容:// uri媒体内容提供商,以便我们可以获得有效的图像ID传递给Thumbnails.getThumbnail。该代码适用于从Camera应用程序(通过startActivityForResult)获取的图像,以及来自库中本地存储在设备上的图像。

我有点难过。

2 个答案:

答案 0 :(得分:0)

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

如果您在安卓的缩略图中遇到困难,请注意以上链接和 api和媒体:group / media:原子提要中的缩略图标签。这是父元素或缩略图的容器引用in this post

所以,为了在android中处理大拇指,如果你可以构建你的代码来实际使用api(picasa feed / photos / media:group等)你可能会有更少的bug问题,比如现在的问题。

示例google / android / picasa code

api ref

another api ref

答案 1 :(得分:0)

有同样的问题,这是导入/包装问题。

确保使用正确的Thumbnail类。那里有两个。一个用于视频,一个用于图像。

MediaStore.Images.Thumbnails
MediaStore.Video.Thumbnails
相关问题