When the super-long image is directly loaded, it may exceed the maximum height of the Bitmap. Using BitmapFactory.Options to zoom the image directly may shrink the image too small, so it is better to use the BitmapRegionDecoder to display the segmented image when loading the long image.
subsampling-scale-image-view
displays this kind of super-long image or super-large image very well, and it is also very good at judging gestures, but it is just a control, it cannot load network resources, it can only be used after other downloads Load it, get the effect
paste code
public class MainActivity extends AppCompatActivity { private SubsamplingScaleImageView scaleImageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); scaleImageView = findViewById(R.id.scale_image_view); // 设置最小缩放比,默认是1 // scaleImageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CUSTOM); // scaleImageView.setMinScale(1.5f); // scaleImageView.setImage(ImageSource.uri("本地路径")); scaleImageView.setImage(ImageSource. asset ( "scale_image_1.jpg" )) ; // set default zoom ratio and initial display position scaleImageView .setScaleAndCenter( 1.5f , new PointF( 0 , 0 )) ; } public void change(View view) { scaleImageView.recycle(); scaleImageView.setImage(ImageSource.asset("scale_image_3.jpg")); scaleImageView.setScaleAndCenter(1.5f, new PointF(0, 0)); } }
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.scaleimage.MainActivity"> <com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView android :id="@+id/scale_image_view" android:layout_width="match_parent" android:layout_height="match_parent" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="换图" android:onClick="change"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout>
长图是随便网上找的,大图是其他人那里拿的,地址是
分辨率6480x3888