Subsampling Zoom Image View - 支持大图的自定义ImageView
jopen
10年前
自定义的Android ImageView。可捏缩放和二次取样瓷砖,支持大图像。
如果你想加载超大图片(1m以上),同时又想让图片可以随意的缩放,还想要流畅的效果,还不想发生oom,那么这个项目绝对是不二的选择。其流畅度与可操作性绝对不输原生相册应用。demo中的图片最大是2.7m,但是一点也不卡。
特性
图片展示
- Display images from assets, resources or the file system
- Automatically rotate images from the file system (e.g. the camera or gallery) according to EXIF
- Manually rotate images in 90° increments
- Swap images at runtime
- Use a custom bitmap decoder
SubsamplingScaleImageViewonly:
- Display huge images, larger than can be loaded into memory
- Show high resolution detail on zooming in
- Tested up to 20,000x13,000px, though larger images are slower
These views don't extendImageViewand aren't intended as a general purpose replacement for it. They're specialised for the display of photos and other large images, not the display of 9-patches, shapes and the other types of drawable that ImageView supports.
手势检测
- One finger pan
- Two finger pinch to zoom
- Quick scale (one finger zoom)
- Pan while zooming
- Seamless switch between pan and zoom
- Fling momentum after panning
- Double tap to zoom in and out
- Options to disable pan and/or zoom gestures
动画
- Public methods for animating the scale and center
- Customisable duration and easing
- Optional uninterruptible animations
重写事件检测
- SupportsOnClickListenerandOnLongClickListener
- Supports interception of events usingGestureDetectorandOnTouchListener
- Extend to add your own gestures
易于集成
- Use within aViewPagerto create a photo gallery
- Easily restore scale, center and orientation after screen rotation
- Can be extended to add overlay graphics that move and scale with the image
- Handles view resizing andwrap_contentlayout
局限
- SubsamplingScaleImageViewrequires SDK 10 (Gingerbread).
- SubsamplingScaleImageViewcannot display aBitmapobject - the image file needs to be in assets, resources or external storage.
- SubsamplingScaleImageViewcannot display grayscale PNGs on Android Lollipop, due to bugs in the skia library and/or BitmapRegionDecoder. Earlier versions of Android also have issues displaying some grayscale PNGs, but not all. I have reported these bugs to Google. For a workaround, see the section on custom bitmap decoders below.
- These views do not extend ImageView so attributes including android:tint, android:scaleType and android:src are not supported.
- Images stored in resources and assets cannot be rotated based on EXIF, you'll need to do it manually. You probably know the orientation of your own files :-)