Skip to content

Commit

Permalink
1.新增支持各个方向上的圆角处理
Browse files Browse the repository at this point in the history
  • Loading branch information
keep2iron committed Apr 3, 2019
1 parent 5f18bc5 commit 5e79784
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.facebook.drawee.generic.RoundingParams
import com.facebook.imagepipeline.request.ImageRequestBuilder
import com.facebook.imagepipeline.image.CloseableImage
import com.facebook.common.references.CloseableReference
import com.facebook.datasource.BaseDataSubscriber
import com.facebook.datasource.DataSource
import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder
import com.facebook.drawee.controller.BaseControllerListener
Expand All @@ -35,7 +34,6 @@ import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber
import com.facebook.imagepipeline.decoder.SimpleProgressiveJpegConfig
import com.facebook.imagepipeline.image.ImageInfo
import com.facebook.imagepipeline.postprocessors.IterativeBoxBlurPostProcessor
import java.util.concurrent.Executor
import java.util.concurrent.Executors

class MatrixScaleType(private val matrix: Matrix) : ScalingUtils.ScaleType {
Expand Down Expand Up @@ -236,8 +234,13 @@ class FrescoImageLoader : ImageLoader {
if (options.isCircleImage) {
loadCircleImage(draweeView)
}
if (options.radius > 0) {
loadRadiusImage(draweeView, options.radius)
if (options.radius > 0 ||
options.radiusTopLeft > 0 ||
options.radiusTopRight > 0 ||
options.radiusBottomLeft > 0 ||
options.radiusBottomRight > 0
) {
loadRadiusImage(draweeView, options)
}
if (options.borderOverlayColor != -1) {
setBorder(draweeView, options.borderOverlayColor, options.borderSize)
Expand Down Expand Up @@ -277,8 +280,26 @@ class FrescoImageLoader : ImageLoader {
draweeView.hierarchy.roundingParams = asCircle
}

private fun loadRadiusImage(draweeView: SimpleDraweeView, radius: Float) {
val cornersRadius = RoundingParams.fromCornersRadius(radius)
private fun loadRadiusImage(draweeView: SimpleDraweeView, options: ImageLoaderOptions) {
if (options.radiusTopLeft == 0f) {
options.radiusTopLeft = options.radius
}
if (options.radiusTopRight == 0f) {
options.radiusTopRight = options.radius
}
if (options.radiusBottomLeft == 0f) {
options.radiusBottomLeft = options.radius
}
if (options.radiusBottomRight == 0f) {
options.radiusBottomRight = options.radius
}

val cornersRadius = RoundingParams.fromCornersRadii(
options.radiusTopLeft,
options.radiusTopRight,
options.radiusBottomLeft,
options.radiusBottomRight
)
draweeView.hierarchy.roundingParams = cornersRadius
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ class ImageLoaderOptions {
/**
* 圆角
*/
var radius: Float = -1f
var radius: Float = 0f
var radiusTopLeft: Float = 0f
var radiusTopRight: Float = 0f
var radiusBottomRight: Float = 0f
var radiusBottomLeft: Float = 0f

/**
* 是否以渐进式方式加载图片 ,仅Fresco支持
*/
Expand Down Expand Up @@ -58,7 +63,8 @@ class ImageLoaderOptions {
/**
* 占位图资源id
*/
@DrawableRes var placeHolderRes:Int = -1
@DrawableRes
var placeHolderRes: Int = -1

var matrix: Matrix? = null

Expand Down

0 comments on commit 5e79784

Please sign in to comment.