BigImageViewer

项目地址: Piasy/BigImageViewer 简介:Big image viewer supporting pan and zoom, with very little memory usage and full featured image loading choices. Powered by Subsampling Scale Image View, Fresco, Glide, and Picasso.

Big image viewer supporting pan and zoom, with very little memory usage and full featured image loading choices. Powered by Subsampling Scale Image View, Fresco, Glide, and Picasso.

Demo

Usage

Dependency

allprojects {    repositories {        maven {            url  "http://dl.bintray.com/piasy/maven"        }    }}compile 'com.github.piasy:BigImageViewer:1.2.7'// load with frescocompile 'com.github.piasy:FrescoImageLoader:1.2.7'// load with glidecompile 'com.github.piasy:GlideImageLoader:1.2.7'// progress pie indicatorcompile 'com.github.piasy:ProgressPieIndicator:1.2.7'

initialize

// MUST use app context to avoid memory leak!// load with frescoBigImageViewer.initialize(FrescoImageLoader.with(appContext));// or load with glideBigImageViewer.initialize(GlideImageLoader.with(appContext));

Note that if you've already used Fresco in your project, please change Fresco.initialize intoBigImageViewer.initialize.

Layout

You can disable display optimization using optimizeDisplay attribute, orBigImageView.setOptimizeDisplay(false). Which will disable animation for long image, and the switch between thumbnail and origin image.

Java

BigImageView bigImageView = (BigImageView) findViewById(R.id.mBigImage);bigImageView.showImage(Uri.parse(url));// you can show thumbnail before the big image is loadedbigImageView.showImage(Uri.parse(thumbnail), Uri.parse(url));

Downloading progress

bigImageView.setProgressIndicator(new ProgressPieIndicator());

There is one built-in indicator, ProgressPieIndicator, you can implement your own indicator easily, learn by example.

Prefetch

You can prefetch images in advance, so it could be shown immediately when user want to see it.

BigImageViewer.prefetch(uris);
bigImageView.setImageSaveCallback(new ImageSaveCallback() {    @Override    public void onSuccess(String uri) {        Toast.makeText(LongImageActivity.this,                "Success",                Toast.LENGTH_SHORT).show();    }    @Override    public void onFail(Throwable t) {        t.printStackTrace();        Toast.makeText(LongImageActivity.this,                "Fail",                Toast.LENGTH_SHORT).show();    }});bigImageView.saveImageIntoGallery();

Get current image file

String path = bigImageView.currentImageFile(); // only valid when image file is downloaded.

Init scale type

mBigImageView.setInitScaleType(BigImageView.INIT_SCALE_TYPE_CENTER_CROP);
value effect
centerInside default, Scale the image so that both dimensions of the image will be equal to or less than the corresponding dimension of the view. The image is then centered in the view. This is the default behaviour and best for galleries.
centerCrop Scale the image uniformly so that both dimensions of the image will be equal to or larger than the corresponding dimension of the view. The image is then centered in the view.
auto determine the max scale and min scale by image size and view size, fit the image to screen and centered when loaded.

You can try the example to checkout the differences! https://fir.im/BIV . Thanks for fir.im!

Caveats

  • Handle permission when you want to save image into gallery.
  • When you want load local image file, you can create the Uri via Uri.fromFile, but the path will be url encoded, and may cause the image loader fail to load it, consider using Uri.parse("file://" + file.getAbsolutePath()).

Why another big image viewer?

There are several big image viewer libraries, PhotoDraweeView, FrescoImageViewer, and Subsampling Scale Image View.

They both support pan and zoom. PhotoDraweeView and FrescoImageViewer both use Fresco to load image, which will cause extremely large memory usage when showing big images. Subsampling Scale Image View uses very little memory, but it can only show local image file.

This library show big image with Subsampling Scale Image View, so it only uses very little memory. And this library support using different image load libraries, so it's full featured!

If you are interested in how does this library work, you can refer to this issue, and Subsampling Scale Image View.

Performance

Memory usage of different libraries:

- PhotoDraweeView FrescoImageViewer BigImageViewer
4135*5134 80MB 80MB 2~20 MB

Todo

  • [x] GlideImageLoader
  • [x] Save image file to gallery
  • [x] Optimize long image showing effect, thanks for razerdp
  • [x] Optimize "double tap to zoom" effect, thanks for razerdp
  • [x] Loading animation
  • [x] Downloading progress
  • [x] Thumbnail support
  • [ ] Component to display image list, with memory optimization
  • [ ] Fail image
  • [ ] Retry when fail
  • [ ] PicassoImageLoader, track this issue

Those features are offered by image load libraries, and they should be easy to implement, but I don't have enough time currently. So your contributions are welcome!

更多相关文章

  1. 第一个ionic项目
  2. ListActivity简介
  3. Android(安卓)ArrayListAdapter泛型类
  4. Android(安卓)项目中常用到的第三方组件
  5. android 项目出现 Theme.AppCompat.Light 的解决方法
  6. android 项目 gradle 命令
  7. Android(安卓)开源项目集合-不定期更新
  8. android项目迁移到androidX:类映射(android.support.v4*)
  9. android项目迁移到androidX:类映射(android.databinding)

随机推荐

  1. 在android中监听呼出电话(电话拦截、修改
  2. android service 组件
  3. Android之——利用系统权限实现手机重启(
  4. android 访问远程数据库与发送email问题
  5. Android屏幕密度(Density)和分辨率概念详解
  6. 英特尔公司面向 Android(安卓)软件开发套
  7. Android(安卓)应用崩溃后重启的机制
  8. Android培训班(60)dex文件格式
  9. 学习android内核 -- 内存管理相关
  10. Android联系人4--联系人查询