Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CropCircleWithBorderTransformation - border radius incorrect #186

Open
fprt77 opened this issue Dec 1, 2020 · 1 comment
Open

CropCircleWithBorderTransformation - border radius incorrect #186

fprt77 opened this issue Dec 1, 2020 · 1 comment

Comments

@fprt77
Copy link

fprt77 commented Dec 1, 2020

TransformationUtils.circleCrop(...) is working with minimal edge (Math.min(destWidth, destHeight)), but CropCircleWithBorderTransformation is drawing border radius using maximal edge.

As a result border is not around image when target width and height are different.

@fprt77
Copy link
Author

fprt77 commented Dec 2, 2020

Fixed transform function should look like this:

  @Override
  protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
                             @NonNull Bitmap toTransform, int outWidth, int outHeight) {

    Bitmap bitmap = TransformationUtils.circleCrop(pool, toTransform, outWidth, outHeight);

    setCanvasBitmapDensity(toTransform, bitmap);

    Paint paint = new Paint();
    paint.setColor(borderColor);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(borderSize);
    paint.setAntiAlias(true);

    int outMinEdge = Math.min(outWidth, outHeight);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawCircle(
      outMinEdge / 2f,
      outMinEdge / 2f,
      outMinEdge / 2f - borderSize / 2f,
      paint
    );

    return bitmap;
  }

I would create PR myself, but I do not have rights to push, since I am not marked as contributor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant