【译】添加图像转换类库

  • 原文链接: 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);

你可能感兴趣的:(【译】添加图像转换类库)