強大的Android大圖查看庫 - BigImageViewer

idku3164 9年前發布 | 16K 次閱讀 安卓開發 Android開發 移動開發

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, andPicasso.

Demo

Usage

Dependency

allprojects {
    repositories {
        jcenter()
    }
}

// NOTE that the artifact id has been changed! compile 'com.github.piasy:BigImageViewer:1.1.3'

// load with fresco compile 'com.github.piasy:FrescoImageLoader:1.1.3'

// load with glide compile 'com.github.piasy:GlideImageLoader:1.1.3'</pre>

initialize

// MUST use app context to avoid memory leak!
// load with fresco
BigImageViewer.initialize(FrescoImageLoader.with(appContext));

// or load with glide BigImageViewer.initialize(GlideImageLoader.with(appContext));</pre>

Note thatif you've already used Fresco in your project, please change Fresco.initialize into BigImageViewer.initialize .

Layout

<com.github.piasy.biv.BigImageView
        android:id="@+id/mBigImage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

Java

BigImageView bigImageView = (BigImageView) findViewById(R.id.mBigImage);
bigImageView.showImage(Uri.parse("http://code2png.babits.top/images/code_1477885912.cpp.png"));

Prefetch

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

BigImageViewer.prefetch(uris);

Save image into gallery

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();</pre>

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!

Performance

Memory usage of different libraries:

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

Todo

  • GlideImageLoader
  • Save image file to gallery
  • Optimize long image showing effect, thanks forrazerdp
  • Optimize "double tap to zoom" effect, thanks forrazerdp
  • PicassoImageLoader, trackthis issue
  • Loading animation
  • Downloading progress
  • Thumbnail support
  • Fail image
  • Retry when fail

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!

 

 

 

 本文由用戶 idku3164 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!