这几天闲着没事就学着做个图片浏览器,做的很简漏,但是还是可以和大家分享一下。其中值得和大家说到的重点有:
一,读取SD卡上面的图片信息
-
- String[] projection = { MediaStore.Images.Thumbnails._ID};
-
-
- Cursor cursor = managedQuery(
- MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
- projection,
- null,
- null,
- null);
- int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
- uriArray = new Uri[cursor.getCount()];
二,将读取的图片生成缩略图
- while(cursor.moveToNext()&&i<cursor.getCount())
- {
- cursor.moveToPosition(i);
- uri = Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,cursor.getInt(columnIndex)+"");
- uriArray[i]=uri;
- try {
- bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
- if (bitmap != null) {
-
- newBitmap = Bitmap.createScaledBitmap(bitmap,80, 80,true);
- bitmap.recycle();
- if (newBitmap != null) {
- publishProgress(new LoadedImage(newBitmap));
- }
- }
- } catch (IOException e) {}
- i++;
- }
很多细节我都加了注释的,希望对读者有所帮助。
下面提供源码下载: http://download.csdn.net/source/3338374