我怎样才能得到缩略图的Picasa图片选自画廊? [英] How Can I Get Thumbnails For Picasa Images Selected From The Gallery?

查看:243
本文介绍了我怎样才能得到缩略图的Picasa图片选自画廊?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,用户能够选择文件的应用程序,无论是新的图像从相机,从库中的图像,或者一个普通的旧文件。然后,它显示了所选择的项目的图标和名称。我有这方面的工作有一个例外。 Gallery应用程序集成Picasa网络相册的照片。如果用户选择从Picasa相册的照片,我没能得到一个缩略图吧。

I'm working on an application where the user is able to select files, either a new image from the camera, an image from the gallery, or a plain old file. It then shows an icon and the name for the selected item. I have this working with one exception. The gallery application integrates picasaweb pictures. If the user selects a picture from a picasa album, I'm not able to get a thumbnail for it.

我使用的是MediaStore.Images.Thumbnails.getThumbnail()方法,它适用于其他图像在画廊就好了,但对Picasa网络相册的文件,我得到的,不管是什么之类的缩略图我尝试得到(虽然MICRO是我后):

I'm using the MediaStore.Images.Thumbnails.getThumbnail() method, and it works for other images in the gallery just fine, but for the picasaweb files, I get, regardless of what "kind" of thumbnail I attempt to get (although MICRO is what I'm after):

ERROR / MiniThumbFile(2051):获得异常读取魔法时,ID =   5634890756050069570,磁盘已满或只读挂载?类   java.lang.IllegalArgumentException异常

ERROR/MiniThumbFile(2051): Got exception when reading magic, id = 5634890756050069570, disk full or mount read-only? class java.lang.IllegalArgumentException

我注意到了URI的给定所选择的文件是不同的。本地图像文件如下:

I noticed the URI's given for the selected files are different. The local image files look like:

内容://媒体/外部/图片/媒体/ 6912

content://media/external/images/media/6912

和Picasa网络相册的网址如下:

and the picasaweb urls look like:

内容://com.android.gallery3d.provider/picasa/item/5634890756050069570

content://com.android.gallery3d.provider/picasa/item/5634890756050069570

我试图用一个查询来获取的原始THUMB_DATA,使用Thumbnails.queryMiniThumbnails(),与Thumbnails.THUMB_DATA投影阵中,但我得到了一个没有这样的列错误。

I attempted to use a query to get at the raw THUMB_DATA, using Thumbnails.queryMiniThumbnails(), with Thumbnails.THUMB_DATA in the projection array, but I got a "no such column" error.

难道还有其他方法获得的缩略图,将更好地工作?而将我有同样的问题,当我试图访问完整的图像数据?

Is there another method for getting thumbnails that would work better? And will I have the same problem when I try and access the full image data?

推荐答案

我所发现的是,在我的Galaxy Nexus的,对于Picassa中的图像存储在一个子目录下的/sdcard/Android/data/com.google .android.apps.plus / cache目录。当内容提供者是com.google.android.gallery3d.provider然后在URL项目后的数字包含图像的名称(在上面的例子5634890756050069570)。此数据correspondes在/sdcard/Android/data/com.google.android.apps.plus/cache下子目录扩展名为。屏幕中的一个文件。如果你要使用DDMS从手机复制此图像(在你的情况5634890756050069570.screen),并以扩展名为.jpeg,你可以打开并查看您的电脑上重新命名。

What I have found is that on my Galaxy Nexus, the images for Picassa are stored in one of subdirectories under the /sdcard/Android/data/com.google.android.apps.plus/cache directory. When the content provider is com.google.android.gallery3d.provider then the number after "item" in the URL contains the name of the image (in your example above "5634890756050069570"). This data correspondes to a file in one of the subdirectories under /sdcard/Android/data/com.google.android.apps.plus/cache with the extension ".screen". If you were to copy this image from your phone (in your case 5634890756050069570.screen) using DDMS and rename it with the extension ".jpeg" you could open it and view it on your computer.

下面的onActivityResult方法将检查该内容提供商返回,然后会递归搜索的/sdcard/Android/data/com.google.android.apps.plus/cache目录中的文件。私有成员变量fileSearchPathResults由递归搜索方法walkDirectoryRecursivelySearchingForFile()填写。

The following onActivityResult method will check for this content provider being returned, and then will recursively search for the file in the /sdcard/Android/data/com.google.android.apps.plus/cache directory. The private member variable fileSearchPathResults is filled in by the recursive search method walkDirectoryRecursivelySearchingForFile().

private String fileSearchPathResult = null;

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };
            String filePath = null;

            // This code is required to get the image path on content providers
            // on API > 10 where the image is from a picassa web album, since Google changed
            // the content provider in versions with API > 10
            if (selectedImage.toString().contains("com.google.android.gallery3d.provider")) {
                StringBuilder contentProviderPath = new StringBuilder(selectedImage.toString());
                int beginningIndex = contentProviderPath.lastIndexOf("/");
                String fileNameWithoutExt = contentProviderPath.subSequence(beginningIndex + 1,
                        contentProviderPath.length()).toString();
                Log.i(TAG, fileNameWithoutExt);
                try {
                    File path = new File("/sdcard/Android/data/com.google.android.apps.plus/cache");
                    if (path.exists() && path.isDirectory()) {
                        fileSearchPathResult = null;
                        walkDirectoryRecursivelySearchingForFile(fileNameWithoutExt, path);
                        if (fileSearchPathResult != null) {
                            filePath = fileSearchPathResult;
                        }
                    }
                } catch (Exception e) {
                    Log.i(TAG, "Picassa gallery content provider directory not found.");
                }
            }
    }


    public void walkDirectoryRecursivelySearchingForFile(String fileName, File dir) {
        String pattern = fileName;

        File listFile[] = dir.listFiles();
        if (listFile != null) {
            for (int i = 0; i < listFile.length; i++) {
                if (listFile[i].isDirectory()) {
                    walkDirectoryRecursivelySearchingForFile(fileName, listFile[i]);
                } else {
                    if (listFile[i].getName().contains(pattern)) {
                        fileSearchPathResult = listFile[i].getPath();
                    }
                }
            }
        }
    }

通过的文件路径,你可以创建具有以下code图像的位图:

With the filePath, you can create a Bitmap of the image with the following code:

        Bitmap sourceImageBitmap = BitmapFactory.decodeFile(filePath);

这篇关于我怎样才能得到缩略图的Picasa图片选自画廊?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆