GithubHelp home page GithubHelp logo

piasy / bigimageviewer Goto Github PK

View Code? Open in Web Editor NEW
4.0K 73.0 400.0 54.59 MB

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. Even with gif and webp support! 🍻

License: MIT License

Java 89.74% Shell 3.57% Kotlin 6.69%

bigimageviewer's Introduction

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. Even with gif and webp support!

Demo

memory usage

pan and zoom gif support
demo gif support

Getting started

Add the dependencies

Note: please put this download url at the first of your repositories part, otherwise, gradle may search in wrong place.

allprojects {
    repositories {
        mavenCentral()
    }
}

implementation 'com.github.piasy:BigImageViewer:1.8.1'

// load with fresco
implementation 'com.github.piasy:FrescoImageLoader:1.8.1'

// load with glide
implementation 'com.github.piasy:GlideImageLoader:1.8.1'

// progress pie indicator
implementation 'com.github.piasy:ProgressPieIndicator:1.8.1'

// support thumbnail, gif and webp with Fresco
implementation 'com.github.piasy:FrescoImageViewFactory:1.8.1'

// support thumbnail and gif with Glide
implementation 'com.github.piasy:GlideImageViewFactory:1.8.1'

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));

// or load with glide custom component
BigImageViewer.initialize(GlideCustomImageLoader.with(appContext, CustomComponentModel.class));

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

Add the BigImageView to your layout

<com.github.piasy.biv.view.BigImageView
        android:id="@+id/mBigImage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:failureImage="@drawable/failure_image"
        app:failureImageInitScaleType="center"
        app:optimizeDisplay="true"
        />

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

Show the image

BigImageView bigImageView = (BigImageView) findViewById(R.id.mBigImage);
bigImageView.showImage(Uri.parse(url));

Usage

Animated image support

Since 1.5.0, BIV support display animated image, e.g. gif and animated webp, to achieve that, you need set a custom ImageViewFactory via biv.setImageViewFactory:

// FrescoImageViewFactory is a prebuilt factory, which use Fresco's SimpleDraweeView
// to display animated image, both gif and webp are supported.
biv.setImageViewFactory(new FrescoImageViewFactory());

// GlideImageViewFactory is another prebuilt factory, which use ImageView to display gif,
// animated webp is not supported (although it will be displayed with ImageView,
// but it won't animate).
biv.setImageViewFactory(new GlideImageViewFactory());

Node: if the image is not gif or animated webp, then it will be displayed by SSIV, the image type is not determined by its file extension, but by its file header magic code.

Thumbnail support

To show a thumbnail before the big image is loaded, you can call below version of showImage:

bigImageView.showImage(Uri.parse(thumbnail), Uri.parse(url));

Note: make sure that you have already called setImageViewFactory.

Shared element transition support (experimental)

Since 1.6.0, BIV has experimental support for shared element transition, but it has following known issues:

  • The shared image may flicker during enter transition, or become white after return transition, when using Fresco, see Fresco issue #1445;
  • The shared image may flicker after return transition, especially after you zoomed SSIV;

You can play with the demo app to evaluate the shared element transition support.

Download progress indicator

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);

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();
    }
});

// should be called on worker/IO thread
bigImageView.saveImageIntoGallery();

Get current image file

// only valid when image file is downloaded.
File path = bigImageView.getCurrentImageFile();

Image init scale type

You can set the normal image scale type using initScaleType attribute, or setInitScaleType.

mBigImageView.setInitScaleType(BigImageView.INIT_SCALE_TYPE_CENTER_CROP);
value effect
center Center the image in the view, but perform no scaling.
centerCrop Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding). The image is then centered in the view.
centerInside Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding). The image is then centered in the view.
fitCenter Scales the image so that it fits entirely inside the parent. At least one dimension (width or height) will fit exactly. Aspect ratio is preserved. Image is centered within the parent's bounds.
fitEnd Scales the image so that it fits entirely inside the parent. At least one dimension (width or height) will fit exactly. Aspect ratio is preserved. Image is aligned to the bottom-right corner of the parent.
fitStart Scales the image so that it fits entirely inside the parent. At least one dimension (width or height) will fit exactly. Aspect ratio is preserved. Image is aligned to the top-left corner of the parent.
fitXY Scales width and height independently, so that the image matches the parent exactly. This may change the aspect ratio of the image.
custom Scale the image so that both dimensions of the image will be equal to or less than the maxScale and equal to or larger than minScale. The image is then centered in the view.
start Scale the image so that both dimensions of the image will be equal to or larger than the corresponding dimension of the view. The top left is shown.

Note: SSIV only support centerCrop, centerInside, custom and start, other scale types are treated as centerInside, while other scale types may be used by animated image types.

Failure image

You can set a local failure image using failureImage attribute, or setFailureImage.

It will displayed using an ImageView when the image network request fails. If not specified, nothing is displayed when the request fails.

Failure image init scale type

You can set the failure image scale type using failureImageInitScaleType attribute, or setFailureImageInitScaleType.

Any value of ImageView.ScaleType is valid. Default value is ImageView.ScaleType.FIT_CENTER. It will be ignored if there is no failure image set.

Tap to retry

When failure image is specified, you can tap the failure image then it will retry automatically. That's the default behavior, you can change it using tapToRetry attribute, or setTapToRetry.

Image load callback

You can handle the image load response by creating a new ImageLoader.Callback and overriding the key callbacks

ImageLoader.Callback myImageLoaderCallback = new ImageLoader.Callback() {
    @Override
    public void onCacheHit(int imageType, File image) {
      // Image was found in the cache
    }

    @Override
    public void onCacheMiss(int imageType, File image) {
      // Image was downloaded from the network
    }

    @Override
    public void onStart() {
      // Image download has started
    }

    @Override
    public void onProgress(int progress) {
      // Image download progress has changed
    }

    @Override
    public void onFinish() {
      // Image download has finished
    }

    @Override
    public void onSuccess(File image) {
      // Image was retrieved successfully (either from cache or network)
    }

    @Override
    public void onFail(Exception error) {
      // Image download failed
    }
}

Then setting it as the image load callback

mBigImageView.setImageLoaderCallback(myImageLoaderCallback);

The onSuccess(File image) is always called after the image was retrieved successfully whether from the cache or the network.

For an example, see ImageLoaderCallbackActivity.java

Cancel image loading

BIV will cancel image loading automatically when detach from window, you can also call cancel to cancel it manually.

You can also call BigImageViewer.imageLoader().cancelAll(); in an appropriate time, e.g. Activity/Fragment's onDestroy callback, to cancel all flying requests, avoiding memory leak.

Full customization

You can get the SSIV instance through the method below:

public SubsamplingScaleImageView getSSIV() {
    return mImageView;
}

Then you can do anything you can imagine about SSIV :)

Note: you should test whether SSIV is null, because the image could be a gif, then it won't be displayed by SSIV.

Custom SSIV support

You can even use your own custom SSIV, by calling biv.setImageViewFactory(), passing in a factory that override createStillImageView, and return your custom SSIV.

Custom Glide components support

You can use your custom Glide's components. If you have customized your Glide's configuration, you are able to apply that configuration to BIV too, to do that you only have to initialize BIV in this way:

BigImageViewer.initialize(GlideCustomImageLoader.with(appContext, CustomComponentModel.class));

Where CustomComponentModel.class is the Glide's model component. That's it!

For more detailed example, please refer to the example project.

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()).

  • When using with RecyclerView or ViewPager, the recycled BIV doesn't know it should clear the loaded image or reload the image, so you need manually notify it in some way, see issue 107, and issue 177.

  • Crash on Android 4.x device? You could force gradle to use a specific version of OkHttp (some version earlier than 3.13.0), by adding this block to your module's build.gradle, please note that it should be added at the top level, not inside any other block:

    configurations {
      all {
        resolutionStrategy {
          eachDependency { DependencyResolveDetails details ->
            if (details.requested.group == 'com.squareup.okhttp3' &&
                details.requested.name ==
                'okhttp') {
              // OkHttp drops support before 5.0 since 3.13.0
              details.useVersion '3.12.6'
            }
          }
        }
      }
    }

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

  • GlideImageLoader
  • Save image file to gallery
  • Optimize long image showing effect, thanks for razerdp
  • Optimize "double tap to zoom" effect, thanks for razerdp
  • Loading animation
  • Downloading progress
  • 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!

When you submit PR, please conform the code style of this project, which is customized from Square Android style.

bigimageviewer's People

Contributors

a1batross avatar acr92 avatar beniozhang avatar drmetallius avatar g19980115 avatar hr avatar kirkbushman avatar mansya avatar nichbar avatar nukc avatar piasy avatar polokoio456 avatar raylee4204 avatar seeeeal avatar smassive avatar swisyn avatar talklittle avatar thakkaryash94 avatar tom5079 avatar xujiaji avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bigimageviewer's Issues

Crash on ProgressView

03-04 19:23:06.687 16550-16550/com.pisces.xsplash.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pisces.xsplash.debug, PID: 16550
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.filippudak.ProgressPieView.ProgressPieView.setProgress(int)' on a null object reference
at com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator.onProgress(ProgressPieIndicator.java:58)
at com.github.piasy.biv.view.BigImageView$1.run(BigImageView.java:84)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

本地图片预览,加载失败

我的图片地址为:/storage/emulated/0/Android/data/com.clds.refractory_of_window_magazine/cache/magazine_open/145/page1.jpg

关于闪烁的问题

关于缩略图加载完之后显示原图有一个非常明显的闪烁过程。
暂时没什么解决思路。。
想请教下大佬。@Piasy

非常感谢。

BigImageView is leaking Memory

I am initializing BigImageViewer with
BigImageViewer.initialize(GlideImageLoader.with(getActivity().getApplicationContext()));

According to LeakCanary, the com.github.piasy.biv.view.BigImageView.mContext is leaking memory.

Any Ideas?

Thanks.

关于巨图加载偶现的卡顿现象以及加载后默认放大填充图片到全屏的建议

// 诶多,那个直接写中文了,感觉表述更直观

在github小伙伴看到您的库,看到底层实现是Subsampling,恰好前段时间项目中也要用到这个库,也遇到了一些问题,在这里分享一下经验顺便提一下意见。。。

1 - 巨图加载偶现卡顿(作者已经优化过,这里只分享一下

对于大多数的超大图片来说,Subsampling都是很nice的,但有些时候,会出现放大后或者移动时会有很卡的问题。

比如这张(上传到图床,保质期不确定):http://p1.bqimg.com/4851/b52ac176b7492815.jpg

如果是使用Subsampling 默认参数的话,就会有上述问题。

看了一些issue#218#244和源码,初步确定是minimumTileDpi问题(该值默认-1),根据该变量定位代码到calculateInSampleSize()方法,我没有细看下去,但初步判定应该是该变量会影响到区域加在栅格的大小(或者缩放?)

所以我在项目中采取了如下计算方法(作者使用的是160固定值)

 DisplayMetrics metrics = this.getResources().getDisplayMetrics();
 //源码为除以2,我采取除以3
 float averageDpi = (metrics.xdpi + metrics.ydpi) / 3.0F;
 imageView.setMinimumTileDpi((int) averageDpi);

2 - 关于默认双击放大图片到全图

这个需求算是用户体验吧,很多时候超大的图都超长的图片(比如微博的长图),一开始都是又细又长,加载完之后就会自动填充到全屏。。。

效果如图(预览似乎失效?图床地址看右边→) http://p1.bqimg.com/4851/b9ccda3171ee6ebc.gif

为了实现这个效果,我使用了OnImageEventListener接口,具体代码如下:

   private SubsamplingScaleImageView.OnImageEventListener onImageEventListener = new SubsamplingScaleImageView.OnImageEventListener() {
        @Override
        public void onReady() {
            if (largeImageView == null) return;
            float result = 0.5f;
            int imageWidth = largeImageView.getSWidth();
            int imageHeight = largeImageView.getSHeight();
            int viewWidth = largeImageView.getWidth() - largeImageView.getPaddingLeft() - largeImageView.getPaddingRight();
            int viewHeight = largeImageView.getHeight() - largeImageView.getPaddingTop() - largeImageView.getPaddingBottom();
            //0值判定
            boolean hasZeroValue = false;
            if (imageWidth == 0 || imageHeight == 0 || viewWidth == 0 || viewHeight == 0) {
                result = 0.5f;
                hasZeroValue = true;
            }
            //非0值则对应计算缩放比率
            if (!hasZeroValue) {
                if (imageWidth <= imageHeight) {
                    result = viewWidth * 1.0f / imageWidth * 1.0f;
                } else {
                    result = viewHeight * 1.0f / imageHeight * 1.0f;
                }
            }
            //动画播放点计算
            if (!isLoadedLargeImage && !hasZeroValue) {
                isLoadedLargeImage = true;
                SubsamplingScaleImageView.AnimationBuilder animationBuilder = null;
                //宽比高小1.5倍,则从顶部开始缩放
                if ((imageHeight * 1.0f / imageWidth * 1.0f) > 1.5f) {
                    animationBuilder =
                        largeImageView.animateScaleAndCenter(result, new PointF(imageWidth / 2, 0))
                                      .withEasing(SubsamplingScaleImageView.EASE_OUT_QUAD);
                } else {
                    largeImageView.animateScaleAndCenter(result, new PointF(viewWidth / 2, viewHeight / 2))
                                  .withEasing(SubsamplingScaleImageView.EASE_OUT_QUAD);
                }
                if (animationBuilder != null) {
                    animationBuilder.start();
                }
            }
            //对结果进行放大裁定,防止计算结果跟双击放大结果过于相近
            if (Math.abs(result - largeDoubleImageScale) < 0.2f) {
                result += 0.2f;
            }
            
            largeImageView.setDoubleTapZoomScale(result);
        }
      
	  //其他方法略
	  
	};

fix memory leak

GlideProgressSupport.DispatchingProgressListener.LISTENERS静态变量,即使调用forget方法,还是会导致承载BigImageView的activity不能释放,造成内存泄漏.
我是用eventbus来解决的,如下:

https://github.com/hss01248/ImageLoader/blob/master/image/src/main/java/com/github/piasy/biv/view/BigImageView.java
https://github.com/hss01248/ImageLoader/blob/master/glideloader/src/main/java/com/hss01248/glideloader/big/GlideProgressSupport.java

用jdk里的订阅者也可以,就是有点繁琐.

用Glide加载图片问题

1.Callback会导致内存泄漏。
2.在图片未加载完成退出再次进入会长时间黑屏。

目前可以解决的办法:在退出fragment或者activity的时候调用Glide.clear(glideDownloadTarget);清除掉当前加载的target。

Error: Could not find com.github.piasy:BigImageViewer:1.2.0.

Hi!

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:25.0.1'
    compile 'com.android.support:design:25.0.1'

    compile 'com.github.piasy:BigImageViewer:1.2.0'
}
allprojects {
    repositories {
        jcenter()
        mavenCentral()
        maven { url "https://www.jitpack.io" }
    }
}

Result:

Error:Could not find com.github.piasy:BigImageViewer:1.2.0.
Required by:
    MyLevel:app:unspecified
<a href="searchInBuildFiles">Search in build.gradle files</a>

关于依赖此项目的问题

在我的项目中无法引用您的这个项目,不知道是什么情况?我的gradle版本是3.1的,用的也是classpath 'com.android.tools.build:gradle:2.2.2'这个版本,可是会报Error:Connection refused: connect

Error inflating class com.github.piasy.biv.view.BigImageView

Caused by: android.view.InflateException: Binary XML file line #21: Binary XML file line #21: Error inflating class com.github.piasy.biv.view.BigImageView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)

scroll thumbnail in zoom mode?

微博里面当图片放大比较大的时候右边和下边都有一个类似scrollbar的drawable,如果要实现这样的效果估计要数学去计算,菜鸟数学太渣,请教下这个应该怎么呢?

NPE on ProgressPieIndicator.onProgress

Hello,
There are times that onProgress throws a NullPointerException when the view has been destroyed but there is still a runnable pending.

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.filippudak.ProgressPieView.ProgressPieView.setProgress(int)' on a null object reference
at com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator.onProgress(ProgressPieIndicator.java:58)
at com.github.piasy.biv.view.BigImageView$1.run(BigImageView.java:84)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)

Question: how does it work?

Does it do downsampling again and again on the same file, or does it load all into JNI, and then just pick the pixels it needs ?

Or maybe it has the option to choose from them ? I mean, it would be a waste to downsample all the time, when you can have it all in the RAM (without being afraid of OOM) ...

无法加载中文命名图片

挺好的库,发现有以上问题,还有就是没必要用rxjava这么大的东西,现在是1.2.5,新版什么时候出,小期待啊

Request Features Callbacks

I try to controller view states image resources... I need capture events

Please add Callbacks support in future:

OnRequestImageSuccesfull -> when donwload image.
OnRequestImageError -> when error download image.
OnRequestImageCache -> when image is retrieve cache.
OnRequestImageCacheError -> when image poblem retieve cache.

请问如何添加请求头?比如Referer

由于有些带有防盗链的图片如果不带Referer将无法请求到真实的图片,我目前使用的是glide+SubsamplingScaleImageView,可以使用glide将图片下载到本地然后再将图片交给SubsamplingScaleImageView来显示,glide自带有添加header的方法所以很方便实现,但是您这个好像是直接使用图片地址请求图片,所以不知道glide+BigImageViewer应该怎么实现携带header请求

fix Fresco progress problem

首先感谢作者这么快添加了进度条显示。然后这个进度并不完美,似乎不是下载的进度,而是解码或者其他东西的进度,我试了好几张大图,一开始好久都不返回进度,后面瞬间就完成了。作者有兴趣的话可以确认一下这个问题,也许是我某些步骤弄错了-_-

cancel action?

Please provide a cancel action, if image is not finish the loading, then user click back, it might produce some weird issue, so could you provide a cancel action for us, that we could use this method to cancel loading, cancel the callback or some... or even something important ** to release memory properly**

Why minSdkVersion = 16?

First of all, thank you for this great lib!

I'd like to use it in my project, but the problem is that minSdkVersion has set to 16. I've copied classes into my project which requires minSdkVersion = 15 and there is no errors? There is mess around after self copying classes rather than aar.

Could you please support older minSdkVersion as much as possible?

Can't set signature (Glide)

Before:
Glide.with(mActivity).load(mediaItem.getUri()) .skipMemoryCache(true) //.asBitmap() //.imageDecoder(new StreamBitmapDecoder(mActivity, DecodeFormat.PREFER_ARGB_8888)) .thumbnail(0.4f) .dontAnimate() .signature(mediaItem.getSignature()) .into(photoView);

after:
photoView.showImage(mediaItem.getUri());

I need to set the signature because I edited my photo and need to reset the glide cache.

OutOfMemory when bitmap cache is under pressure

I think you need to implement bitmap caching inside of SubsamplingScaleImageView, cause it may be that SubsamplingScaleImageView will have OOM exception on a devices with large screens and small amount of RAM.

小图无法缩放问题

我加载一张小图 图片宽高都小于屏幕 结果无法缩放 我想问下是SSIV的问题 还是BigImageViewer的问题

加载进度和缩略图显示问题

用的fresco,存在两个问题:
1.进度一直为0
2.设置了缩略图(网络,图片很小),本来应该是先很快加载缩略图,然后等了一会加载大图,但现在是空白页面等很长时间,然后缩略图闪过,然后立马就出来大图.

没必要为了请求权限而加上RxJava和RxPermissions。

BigImageViewer加了rxjava 与 rxpermissions的依赖,作用仅仅是判断和请求一下存储时的权限。但我认为这个请求权限的动作不该由BigImageViewer这个框架来完成。仅仅为了一个权限加上了一个很大的rxjava2库。还会导致与其他使用rxjava1.x导致不兼容。

保存gif問題

現在圖片默認是png結尾的,導致保存gif有問題

Progress and thumbnail support proposal

As more and more people reach out this library, I'd like to share my thoughts about these two features before coding.

Progress

Fresco support progress notification, so it's easy to add it in FrescoImageLoader, but Glide doesn't support this feature yet. So we need use OkHttp intercepter to get progress, here is a example.

Thumbnail

Thumbnail image need also to be loaded, but it could be loaded into normal ImageView or SimpleDraweeView. I want to implement this feature in loader module.

With Fresco loader, we know whether a request will hit or miss the cache, we can skip the thumbnail loading if we hit the cache.

But with Glide loader, we couldn't know whether a request will hit or miss the cache, but a cache hit won't trigger HTTP request, so we could start loading the thumbnail when the HTTP request starts.

不支持旋转

ps:SubsamplingScaleImageView在viewpager中根据exif旋转会oom

Clear cache?

Hi, I'm using your app to load images that are being changed on the server every few minutes and I'd like to load new ones. Unfortunately, when an image is loaded with this library, it is stored in the cache and you can't view new image. I'd suggest you to add something like bigImageView.useCache(false);. Currently, I'm using this code to clear cache, but it's not perfect, I guess... (cache clearing provided by the library would be better):

@Override
protected void onStop(){
    super.onStop();
}
@Override
protected void onDestroy() {
    super.onDestroy();
    try {
        trimCache(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
public static void trimCache(Context context) {
    try {
        File dir = context.getCacheDir();
        if (dir != null && dir.isDirectory()) {
            deleteDir(dir);
        }
    } catch (Exception e) {
    }
}
public static boolean deleteDir(File dir) {
    if (dir != null && dir.isDirectory()) {
        String[] children = dir.list();
        for (int i = 0; i < children.length; i++) {
            boolean success = deleteDir(new File(dir, children[i]));
            if (!success) {
                return false;
            }
        }
    }
    return dir.delete();
}

ViewPager 使用BigImageViewer 时,造成大量内存无法释放。

在Adapter 中的代码如下

@Override
    public Object instantiateItem(ViewGroup container, int position) {
        String viewType = list.get(position).getType();
        if ("html".equals(viewType)) {
            WebView view = new WebView(context);
            view.loadUrl(list.get(position).getPath());
            view.setWebViewClient(new WebViewClient() {
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    view.loadUrl(url);// 根据传入的参数再去加载新的网页
                    return true;// 表示当前webview可以处理打开新网页的请求,不用借助系统浏览器
                }
            });
            WebSettings settings = view.getSettings();
            settings.setJavaScriptEnabled(true);
            view.addJavascriptInterface(new Isjs(), "clds");


            container.addView(view);
//            views.add(position,view);
            return view;
        } else {
            BigImageView view = new BigImageView(context);

            Uri uri = Uri.parse(list.get(position).getPath());
            Uri suouri = Uri.parse(list.get(position).getPath());
            view.showImage(uri);
//            view.showImage(suouri,uri);

            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    toSing.isShow();
                }
            });
            container.addView(view);


            return view;
        }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.