欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android 圖片處理縮放功能

 更新時間:2018年06月21日 16:26:47   作者:CMusketeer  
這篇文章主要介紹了Android 圖片處理縮放功能,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下

PS:在開發(fā)中我們會遇到一些圖片處理問題,比如說緩存圖片了、限制圖片大小了、查看圖片了等。上一篇文章介紹了圖片的全景效果查看,今天介紹一個圖片縮放,我們?nèi)绻袝r間的話,可以自己寫一個屬于自己的庫,里面會用到view的按壓、事件分發(fā)、手勢等一些知識,如果沒有時間或者不會其他的方法,不妨來看看這個PhotoView。這是一個圖片縮放庫,對于這樣的還有GitView等,下面我就介紹一些用法。

功能:

  • 正常加載圖片
  • 雙擊放大
  • 手勢隨意縮放
  • 隨意拖動查看圖片每一個角落
  • 結合其他設置可實現(xiàn)翻轉(zhuǎn)

效果圖

1:本地圖片加載

<ImageView
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:id="@+id/id_loc"
    android:scaleType="fitXY"
    />
<uk.co.senab.photoview.PhotoView
    android:layout_width="match_parent"
    android:layout_height="400dp"
    android:src="@mipmap/ic_launcher"
    android:id="@+id/id_myimg"/>

第一種方法:

 //本地加載方法一
    // 設置圖片
    Drawable bitmap = getResources().getDrawable(R.mipmap.ic_launcher);
    loc.setImageDrawable(bitmap);
    // 連接在photoview中
    PhotoViewAttacher mAttacher = new PhotoViewAttacher(loc);
    mAttacher.update();//更新 

第二種

//本地方法加載二
    PhotoViewAttacher mAttacher;
    mAttacher = new PhotoViewAttacher(loc);
    iv.setImageBitmap(bitmap);
    Glide.with(this).load(R.mipmap.ic_launcher).asBitmap().into(loc);
    mAttacher.update();

 2:網(wǎng)絡圖片加載

對于網(wǎng)絡也是可以用ImageView和PhotoView兩種

把ImageView或者PhotoView的對象名直接添加到display中就OK 了。    

//加載網(wǎng)絡圖片
    ImageLoader loader= ImageLoader.getInstance();
    loader.init(ImageLoaderConfiguration.createDefault(ImageTest.this));//loader初始化
    loader.displayImage("https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1529211252&di=1414331e22239ecb5730cbbd0f3793eb&src=http://pic154.nipic.com/file/20180114/26629113_090329120799_2.jpg",loc);//展示圖片

下面我們可以看一下源碼,其實他也是繼承了ImageView

/**
   * Adds display image task to execution pool. Image will be set to ImageView when it's turn. <br/>
   * Default {@linkplain DisplayImageOptions display image options} from {@linkplain ImageLoaderConfiguration
   * configuration} will be used.<br />
   * <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call
   *
   * @param uri    Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
   * @param imageView {@link ImageView} which should display image
   * @throws IllegalStateException  if {@link #init(ImageLoaderConfiguration)} method wasn't called before
   * @throws IllegalArgumentException if passed <b>imageView</b> is null
   */
  public void displayImage(String uri, ImageView imageView) {
    displayImage(uri, new ImageViewAware(imageView), null, null, null);
  }

總結

以上所述是小編給大家介紹的Android 圖片處理縮放功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關文章

最新評論