wasabeef / glide-transformations

An Android transformation library providing a variety of image transformations for Glide.
Apache License 2.0
9.9k stars 1.41k forks source link

No border #190

Open slavzilla opened 3 years ago

slavzilla commented 3 years ago

This is more a request than an issue. If you pass borderSize = 0 it actually is not 0 it is 1 pixel. This is an issue if you want to generalize a function let's say like this:

fun ImageView.loadCircularImage(uri: String?, width: Float){ val options = RequestOptions() .placeholder(android.R.color.transparent) Glide.with(context).setDefaultRequestOptions(options).load(uri) .apply(RequestOptions.bitmapTransform(CropCircleWithBorderTransformation(context.dp2px(width), Color.WHITE))) .into(this) }

If I want no border I would simply pass 0 to this function but It won't actually work because of this: paint.setStrokeWidth(borderSize); I could use CropCircleTransformation but it is deprecated.

slavzilla commented 3 years ago

You can have a workaround for this particular case like this: fun ImageView.loadCircularImage(uri: String?, width: Float){ val options = RequestOptions() .placeholder(android.R.color.transparent) Glide.with(context).setDefaultRequestOptions(options).load(uri) .apply { if (width > 0){ apply(RequestOptions.bitmapTransform(CropCircleWithBorderTransformation(context.dp2px(width), Color.WHITE))) } else { apply(RequestOptions.circleCropTransform()) } } .into(this) } But this is not really a solution, right? 0 is still not 1.

bryantmero commented 2 years ago

@slavzilla , I have used: fun ImageView.loadCircularImage(uri: String?, width: Float){ val options = RequestOptions() .placeholder(android.R.color.transparent) Glide.with(context).setDefaultRequestOptions(options).load(uri) .apply { if (width > 0){ apply(RequestOptions.bitmapTransform(CropCircleWithBorderTransformation(context.dp2px(width), Color.WHITE))) } else { apply(RequestOptions.circleCropTransform()) } } .into(this) }

But not getting expected result either

slavzilla commented 2 years ago

@slavzilla , I have used: fun ImageView.loadCircularImage(uri: String?, width: Float){ val options = RequestOptions() .placeholder(android.R.color.transparent) Glide.with(context).setDefaultRequestOptions(options).load(uri) .apply { if (width > 0){ apply(RequestOptions.bitmapTransform(CropCircleWithBorderTransformation(context.dp2px(width), Color.WHITE))) } else { apply(RequestOptions.circleCropTransform()) } } .into(this) }

But not getting expected result either

Yeah man, I eventually gave up. Nobody replied for like two years...