强大的Android大图查看库 - BigImageViewer
idku3164
8年前
<h2><strong>BigImageViewer</strong></h2> <p>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.</p> <h2><strong>Demo</strong></h2> <p><img src="https://simg.open-open.com/show/a9eb6f38a06b813165bf1e2dbc3dfa87.png"></p> <p style="text-align: center;"><img src="https://simg.open-open.com/show/f4c0d9e57d5c1bde9c758d59b2fd7d74.gif"></p> <p style="text-align: center;"><img src="https://simg.open-open.com/show/78da203bd21048bf59b6a4e1171838cb.gif"></p> <h2><strong>Usage</strong></h2> <h3><strong>Dependency</strong></h3> <pre> 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> <h3><strong>initialize</strong></h3> <pre> // 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> <p>Note thatif you've already used Fresco in your project, please change Fresco.initialize into BigImageViewer.initialize .</p> <h3><strong>Layout</strong></h3> <pre> <com.github.piasy.biv.BigImageView android:id="@+id/mBigImage" android:layout_width="match_parent" android:layout_height="match_parent" /></pre> <h3><strong>Java</strong></h3> <pre> BigImageView bigImageView = (BigImageView) findViewById(R.id.mBigImage); bigImageView.showImage(Uri.parse("http://code2png.babits.top/images/code_1477885912.cpp.png"));</pre> <h3><strong>Prefetch</strong></h3> <p>You can prefetch images in advance, so it could be shown immediately when user want to see it.</p> <pre> BigImageViewer.prefetch(uris);</pre> <h3><strong>Save image into gallery</strong></h3> <pre> 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> <h2><strong>Why another big image viewer?</strong></h2> <p>There are several big image viewer libraries,PhotoDraweeView,FrescoImageViewer, and Subsampling Scale Image View .</p> <p>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.</p> <p>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!</p> <h2><strong>Performance</strong></h2> <p>Memory usage of different libraries:</p> <table> <thead> <tr> <th>-</th> <th>PhotoDraweeView</th> <th>FrescoImageViewer</th> <th>FrescoBigImageViewer</th> </tr> </thead> <tbody> <tr> <td>4135*5134</td> <td>80MB</td> <td>80MB</td> <td>2~20 MB</td> </tr> </tbody> </table> <h2><strong>Todo</strong></h2> <ul> <li>GlideImageLoader</li> <li>Save image file to gallery</li> <li>Optimize long image showing effect, thanks forrazerdp</li> <li>Optimize "double tap to zoom" effect, thanks forrazerdp</li> <li>PicassoImageLoader, trackthis issue</li> <li>Loading animation</li> <li>Downloading progress</li> <li>Thumbnail support</li> <li>Fail image</li> <li>Retry when fail</li> </ul> <p>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!</p> <p> </p> <p> </p> <p> </p>