public void selectRandomImage()
{
Cursor c = getContentResolver().query( Images.Media.EXTERNAL_CONTENT_URI, null, null, null, null );
if ( c != null ) {
int count = c.getCount();
int position = (int)( Math.random() * count );
if ( c.moveToPosition( position ) ) {
long id = c.getLong( c.getColumnIndex( Images.Media._ID ) );
int orientation = c.getInt( c.getColumnIndex( Images.Media.ORIENTATION ) );
Uri imageUri = Uri.parse( Images.Media.EXTERNAL_CONTENT_URI + "/" + id );
Bitmap bitmap;
try {
bitmap = ImageLoader.loadFromUri( this, imageUri.toString(), 1024, 1024 );
mImageView.setImageBitmapReset( bitmap, orientation, true );
}
catch ( IOException e ) {
Toast.makeText( this, e.toString(), Toast.LENGTH_LONG ).show();
}
}
c.close();
c = null;
return;
}
}
Anyway, if you want to download the source, here is the eclipse source project:
http://blog.sephiroth.it/wp-…/ImageZoom.zip
No comments:
Post a Comment