新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
怎么在Android中使用Picasso加載網(wǎng)絡(luò)圖片-創(chuàng)新互聯(lián)
怎么在Android中使用Picasso加載網(wǎng)絡(luò)圖片?很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
通過Picasso來縮放
其實picasso提供了這樣的方法。具體是顯示Transformation 的 transform 方法。
(1) 先獲取網(wǎng)絡(luò)或本地圖片的寬高
(2) 獲取需要的目標(biāo)寬
(3) 按比例得到目標(biāo)的高度
(4) 按照目標(biāo)的寬高創(chuàng)建新圖
Transformation transformation = new Transformation() { @Override public Bitmap transform(Bitmap source) { int targetWidth = mImg.getWidth(); LogCat.i("source.getHeight()="+source.getHeight()); LogCat.i("source.getWidth()="+source.getWidth()); LogCat.i("targetWidth="+targetWidth); if(source.getWidth()==0){ return source; } //如果圖片小于設(shè)置的寬度,則返回原圖 if(source.getWidth()之后在Picasso設(shè)置transform
Picasso.with(mContext) .load(imageUrl) .placeholder(R.mipmap.zhanwei) .error(R.mipmap.zhanwei) .transform(transformation) .into(viewHolder.mImageView);Transformation 這是Picasso的一個非常強(qiáng)大的功能了,它允許你在load圖片 -> into ImageView 中間這個過成對圖片做一系列的變換。比如你要做圖片高斯模糊、添加圓角、做度灰處理、圓形圖片等等都可以通過Transformation來完成。
看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進(jìn)一步的了解或閱讀更多相關(guān)文章,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對創(chuàng)新互聯(lián)的支持。
文章名稱:怎么在Android中使用Picasso加載網(wǎng)絡(luò)圖片-創(chuàng)新互聯(lián)
URL標(biāo)題:http://www.ef60e0e.cn/article/djchdh.html