如何使用包含图像(* .jpg)的文件夹中的缩略图填充图库?

时间:2011-10-11 14:49:49

标签: android android-gallery

这是我用来填充我的画廊的代码。

//--------------------------------------------
        final Cursor cursor;
        final int columnIndex;

        Gallery g = (Gallery) findViewById(R.id.gallery);
        // request only the image ID to be returned
        String[] projection = {MediaStore.Images.Media._ID};
        // Create the cursor pointing to the SDCard

        cursor = managedQuery(
                //uu.build(),
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                projection, 
                MediaStore.Images.Media.DATA + " like ? ",
                new String[] {"%MyIdentityPhotos%"},  
                null);
        cursor.moveToFirst();
        // Get the column index of the image ID
        columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);

        g.setAdapter(new BaseAdapter() {
            public int getCount() {
              return cursor.getCount();
            }
            public Object getItem(int position) {

                // Move cursor to current position
                cursor.moveToPosition(position);
                // Get the current value for the requested column
                int imageID = cursor.getInt(columnIndex);
                // obtain the image URI
                Uri uri = Uri.withAppendedPath( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID) );
                String url = uri.toString();
                // Set the content of the image based on the image URI
                int originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length()));
                return MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(),
                                originalImageId, MediaStore.Images.Thumbnails.MINI_KIND, null);

            }

            public long getItemId(int position) {
              return position;
            }

            public View getView(int position, View convertView, ViewGroup parent) {
                ImageView i = new ImageView(ImViewer.this);
                // Move cursor to current position
                cursor.moveToPosition(position);
                // Get the current value for the requested column
                int imageID = cursor.getInt(columnIndex);
                // obtain the image URI
                Uri uri = Uri.withAppendedPath( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID) );
                String url = uri.toString();
                // Set the content of the image based on the image URI
                int originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length()));
                Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(),
                                originalImageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
                i.setImageBitmap(b);

                Display display = getWindowManager().getDefaultDisplay(); 
                int width = display.getWidth();
                //int height = display.getHeight();

                i.setLayoutParams(new Gallery.LayoutParams(width, (int) (width / 0.77) ));
                i.setScaleType(ImageView.ScaleType.CENTER_CROP );
                //i.setBackgroundResource(mGalleryItemBackground);
                return i;
            }

          });
        //--------------------------------------------

这对我来说不合适,因为这只会将图像转移到内置于图库中的android中。

我正在寻找的是使用特定文件夹做同样的事情。

提前致谢

0 个答案:

没有答案