- 原文鏈接: Additional Transformations with Transformation Library
- 原文作者: Future Studio
- 譯文出自: 小鄧子的簡書
- 譯者: 小鄧子
- 狀態: 完成
Picasso圖像轉換類庫
如果你已經有了一個圖像轉換的想法,希望在應用中使用,可以花上幾分鐘的時間,了解一下picasso-transformations這個三方類庫。它是一個提供了各種Picasso轉換的方法集合。對于你的實現來說,它非常值得學習。
這個類庫有兩個不同的版本。其中擴展版本包含更豐富的圖像轉換,使用設備的GPU進行計算與渲染。需要一個額外的依賴,所以添加這兩個版本的方式有些不同。你應該通過轉換類型列表,來決定哪個版本是真正需要的。
設置Picasso圖像轉換
設置方式非常的簡單!對于基礎版本的轉換,你只需在build.gradle
中添加一行命令:
dependencies {
compile 'jp.wasabeef:picasso-transformations:2.1.0'
}
如果你需要用到GPU方面的圖形轉換:
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile 'jp.wasabeef:picasso-transformations:2.1.0'
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
}
圖形轉換的運用
當build.gradle
文件完成同步操作之后,你就可以使用轉換集合中的任何一種了。使用方式與你自定義圖像轉換器無異。假設,我們希望將圖像裁剪成圓形:
Picasso
.with(context)
.load(UsageExampleListViewAdapter.eatFoodyImages[0])
.transform(new CropCircleTransformation())
.into(imageViewTransformationBlur);
你也可以通過鏈式調用,為Picasso請求同時添加多個圖像轉換器:
int color = Color.parseColor("#339b59b6");
Picasso
.with(context)
.load(UsageExampleListView.eatFoodyImages[0])
.transform(new ColorFilterTransformation(color))
.transform(new CropCircleTransformation())
.into(imageViewTransformationLibrary);