Android圖片處理--縮放

來源:互聯網
上載者:User

標籤:parent   file   http   plain   create   string   androi   exception   ali   

PS:在開發中我們會遇到一些圖片處理問題,比如說緩衝圖片了、限制圖片大小了、查看圖片了等。上一篇文章介紹了圖片的全景效果查看,今天介紹一個圖片縮放,我們如果有時間的話,可以自己寫一個屬於自己的庫,裡面會用到view的按壓、事件分發、手勢等一些知識,如果沒有時間或者不會其他的方法,不妨來看看這個PhotoView。這是一個圖片縮放庫,對於這樣的還有GitView等,下面我就介紹一些用法。功能:
  • 正常載入圖片
  • 雙擊放大
  • 手勢隨意縮放
  • 隨意拖動查看圖片每一個角落
  • 結合其他設定可實現翻轉

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:網狀圖片載入

對於網路也是可以用ImageView和PhotoView兩種

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

        //載入網狀圖片        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圖片處理--縮放

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.