Android 调用系统图片浏览器

来源:互联网 发布:淘宝销量多久清零 编辑:程序博客网 时间:2024/05/01 16:31

http://www.blogbus.com/java-android-logs/151611473.html

在做各种项目的时候会经常遇到需要调用系统图片查看器来查看自己需要查看的图片,因为这样就可以在图片上实现多点触摸,放大和缩小,并且在提高效率的同时又能有很好的体验。

下面的代码便是调用系统图片查看器来查看自己的图片的关键代码:

//获取你选中的是那一张图片(ID值)

int pos = mGallery.getSelectedItemPosition();

//判断此ID值是不是-1,及表示有没有选中图片,没有选中图片为-1,其次为选中

if (pos == AdapterView.INVALID_POSITION)
      return;

//下方是将ImageList集合中的图片路径转换为可供File识别的String数据,
String value = String.valueOf(mImagesList.get(pos).getPicturePath());
File file = new File(value);

//下方是是通过Intent调用系统的图片查看器的关键代码
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "image/*");
startActivity(intent);

0 0