当前位置: 首页 > 软件库 > 手机/移动开发 > >

subsampling-scale-image-view

授权协议 Apache-2.0 License
开发语言 Java
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 宗增
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Subsampling Scale Image View

A custom image view for Android, designed for photo galleries and displaying huge images (e.g. maps and building plans) without OutOfMemoryErrors. Includes pinch to zoom, panning, rotation and animation support, and allows easy extension so you can add your own overlays and touch event detection.

The view optionally uses subsampling and tiles to support very large images - a low resolution base layer is loaded and as you zoom in, it is overlaid with smaller high resolution tiles for the visible area. This avoids holding too much data in memory. It's ideal for displaying large images while allowing you to zoom in to the high resolution details. You can disable tiling for smaller images and when displaying a bitmap object. There are some advantages and disadvantages to disabling tiling so to decide which is best, see the wiki.

Guides

Migration guides

Versions 3.9.0, 3.8.0 and 3.0.0 contain breaking changes. Migration instructions can be found in the wiki.

Download the sample app

Kotlin Sample App on GitHub

Demo

Features

Image display

  • Display images from assets, resources, the file system or bitmaps
  • Automatically rotate images from the file system (e.g. the camera or gallery) according to EXIF
  • Manually rotate images in 90° increments
  • Display a region of the source image
  • Use a preview image while large images load
  • Swap images at runtime
  • Use a custom bitmap decoder

With tiling enabled:

  • Display huge images, larger than can be loaded into memory
  • Show high resolution detail on zooming in
  • Tested up to 20,000x20,000px, though larger images are slower

Gesture detection

  • 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

Animation

  • Public methods for animating the scale and center
  • Customisable duration and easing
  • Optional uninterruptible animations

Overridable event detection

  • Supports OnClickListener and OnLongClickListener
  • Supports interception of events using GestureDetector and OnTouchListener
  • Extend to add your own gestures

Easy integration

  • Use within a ViewPager to 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 and wrap_content layout

Quick start

1) Add this library as a dependency in your app's build.gradle file.

dependencies {
    implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0'
}

If your project uses AndroidX, change the artifact name as follows:

dependencies {
    implementation 'com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0'
}

2) Add the view to your layout XML.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

3a) Now, in your fragment or activity, set the image resource, asset name or file path.

SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(id.imageView);
imageView.setImage(ImageSource.resource(R.drawable.monkey));
// ... or ...
imageView.setImage(ImageSource.asset("map.png"))
// ... or ...
imageView.setImage(ImageSource.uri("/sdcard/DCIM/DSCM00123.JPG"));

3b) Or, if you have a Bitmap object in memory, load it into the view. This is unsuitable for large images because it bypasses subsampling - you may get an OutOfMemoryError.

SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(id.imageView);
imageView.setImage(ImageSource.bitmap(bitmap));

Photo credits

About

Copyright 2018 David Morrissey, and licensed under the Apache License, Version 2.0. No attribution is necessary but it's very much appreciated. Star this project if you like it!

  • Android中的图片加载一直是很重要的一块,也是很令人头疼的一块,动不动就出现OOM。所以我们有fresco等优秀的第三方框架,什么三级缓存,一行代码就帮我们轻松实现。但当面对超级长超级大分辨率尺寸的图时,就显得无能为力了,如果直接加载到内存中就又会出现OOM。 1.BitmapRegionDecoder 实现长图大图的加载,最关键的类就是BitmapRegionDecoder他可以实现对图片的

  • 超长图直接加载的时候有可能会出现超出Bitmap最大高度,直接使用BitmapFactory.Options来缩放图片可能会把图片缩的太小,所以加载长图最好还是用BitmapRegionDecoder来进行分段显示。 subsampling-scale-image-view显示这种超长图或超大图效果很好,而且对手势判断也做的非常好,不过它只是一个控件,不能加载网络资源,只能通过其他下载后再用它进行

  •  Android加载/处理超大图片神器!SubsamplingScaleImageView(subsampling-scale-image-view)【系列1】 Android在加载或者处理超大巨型图片(x MB量级起步的图片)是一件非常需要小心谨慎的活儿,除了常规的OOM,其他需要处理的细节地方还很多,幸好开源社区github贡献了一套神器:SubsamplingScaleImageView

  • Android在加载图片过大,或加载图片资源过多,来不及释放时,就会出现OOM(Out Of Memory)情况;  

  • Android在加载或者处理超大巨型图片(x MB量级起步的图片)是一件非常需要小心谨慎的活儿,除了常规的OOM,其他需要处理的细节地方还很多,幸好开源社区github贡献了一套神器:SubsamplingScaleImageView(subsampling-scale-image-view),提供了一揽子完善的Android超大巨图的解决处理方案,为开发者解决处理加载超大巨型图的燃眉之急。 Su

  •  Android加载/处理超大图片神器!SubsamplingScaleImageView(subsampling-scale-image-view)【系列1】 Android在加载或者处理超大巨型图片(x MB量级起步的图片)是一件非常需要小心谨慎的活儿,除了常规的OOM,其他需要处理的细节地方还很多,幸好开源社区github贡献了一套神器:SubsamplingScaleImageView

  • 前言 代码仓库地址 在Android平台,用户再查看图片的时候,都有放大缩小图片的需求,放大的主要目的是观察图片的细节。Android提供了ImageView作为展示图片的官方控件,很遗憾,ImageView无法实现这个效果,有人说了,可以通过Matrix矩阵来实现啊,确实通过Matrix可以实现图片的放大或者缩小,但是ImageView完全加载一张大图片的内存代价是惊人的,这种实现方式很容易爆掉

 相关资料
  • Data Model Inference Criticism Classes Compositionality Data Subsampling Development Data Subsampling Running algorithms which require the full data set for each update can be expensive when the data

  • The scale component defines a shrinking, stretching, or skewing transformation of an entity. It takes three scaling factors for the X, Y, and Z axes. All entities inherently have the scale component.

  • 描述 (Description) Scale效果可以与show/hide/toggle一起使用。 这会按百分比因子缩小或增加元素。 语法 (Syntax) 以下是使用此效果的简单语法 - <i>selector</i>.hide|show|toggle( "scale", {arguments}, speed ); 参数 (Parameters) 以下是所有论点的描述 - direction -

  • “缩放”小组件提供了一个图形滑块对象,允许您从特定比例中选择值。 语法 (Syntax) 以下是创建此小部件的简单语法 - w = Scale ( master, option, ... ) 参数 (Parameters) master - 这表示父窗口。 options - 以下是此小部件最常用的选项列表。 这些选项可用作以逗号分隔的键值对。 Sr.No. 选项和说明 1 activeback

  • 对于可视化来说,比例尺是一个很方便的工具:将抽象的维度数据映射为可视化表示。虽然经常使用位置编码定量数据,比如将测量单位米使用像素映射。但是比例尺可以对任何视觉编码进行映射,比如颜色,描边的宽度或者符号的大小。比例尺也可以用来对任意类型的数据进行映射,比如分类数据或离散的数据。 对于 Installing NPM 安装:npm install d3-scale. 此外还可以下载 latest re

  • 描述 (Description) java.math.BigDecimal.scale()返回此BigDecimal的比例。 如果为零或正数,则比例是小数点右侧的位数。 如果是负数,则将数字的未缩放值乘以10来表示比例的否定。 例如,比例为-3表示未缩放的值乘以1000。 声明 (Declaration) 以下是java.math.BigDecimal.scale()方法的声明。 public i