【譯】添加圖像轉(zhuǎn)換類庫

Picasso圖像轉(zhuǎn)換類庫

如果你已經(jīng)有了一個圖像轉(zhuǎn)換的想法,希望在應(yīng)用中使用,可以花上幾分鐘的時間,了解一下picasso-transformations這個三方類庫。它是一個提供了各種Picasso轉(zhuǎn)換的方法集合。對于你的實現(xiàn)來說,它非常值得學(xué)習(xí)。

這個類庫有兩個不同的版本。其中擴(kuò)展版本包含更豐富的圖像轉(zhuǎn)換,使用設(shè)備的GPU進(jìn)行計算與渲染。需要一個額外的依賴,所以添加這兩個版本的方式有些不同。你應(yīng)該通過轉(zhuǎn)換類型列表,來決定哪個版本是真正需要的。

設(shè)置Picasso圖像轉(zhuǎn)換

設(shè)置方式非常的簡單!對于基礎(chǔ)版本的轉(zhuǎn)換,你只需在build.gradle中添加一行命令:

dependencies {  
    compile 'jp.wasabeef:picasso-transformations:2.1.0'
}

如果你需要用到GPU方面的圖形轉(zhuǎn)換:

repositories {  
    jcenter()
    mavenCentral()
}

dependencies {  
    compile 'jp.wasabeef:picasso-transformations:2.1.0'
    compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
}

圖形轉(zhuǎn)換的運用

當(dāng)build.gradle文件完成同步操作之后,你就可以使用轉(zhuǎn)換集合中的任何一種了。使用方式與你自定義圖像轉(zhuǎn)換器無異。假設(shè),我們希望將圖像裁剪成圓形:

Picasso  
    .with(context)
    .load(UsageExampleListViewAdapter.eatFoodyImages[0])
    .transform(new CropCircleTransformation())
    .into(imageViewTransformationBlur);

你也可以通過鏈?zhǔn)秸{(diào)用,為Picasso請求同時添加多個圖像轉(zhuǎn)換器:

int color = Color.parseColor("#339b59b6");

Picasso  
        .with(context)
        .load(UsageExampleListView.eatFoodyImages[0])
        .transform(new ColorFilterTransformation(color))
        .transform(new CropCircleTransformation())
        .into(imageViewTransformationLibrary);
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容