user7285912
user7285912

Reputation: 201

XAMARIN ANDROID: Anti-Aliasing issue

we have created a method that cuts a circle form an image and then displays it with a border. The problem is, that even though anti-aliasing is set on "true" it looks like this: Missing Anti-Aliasing

You can clearly see, that the round image is very pixelated. This is a screenshot from an Samsung S6 which we use to debug.

This is the code in question:

public static Bitmap DrawBorder(Bitmap bitmap)
{
    float ratio = 0.97f;
    int width = bitmap.Width;
    int height = bitmap.Height;
    Bitmap outputBitmap = Bitmap.CreateBitmap(width, height, Config.Argb8888);

Path path = new Path();
Canvas canvas = new Canvas(outputBitmap);

//Draw Border
Paint paint = new Paint();
paint.AntiAlias = true;
paint.SetStyle(Paint.Style.Fill);
paint.SetXfermode(null);
//   paint.SetStyle(Paint.Style.Stroke);
paint.Color = Color.White;
//   paint.StrokeWidth = 6;
canvas.DrawCircle((float)width / 2, (float)height / 2, (float)Math.Min(width / 2, (height / 2)), paint);

//Draw Picture 
path.AddCircle(
          (float)(width / 2)
        , (float)(height / 2)
        , (float)Math.Min(width / 2, (height / 2)) * ratio
        , Path.Direction.Ccw);

canvas.ClipPath(path);
canvas.DrawBitmap(bitmap, 0, 0, paint);



return outputBitmap;

}

Can anybody hint us towards the right direction? That'd be awesome :)

THANKS!

Upvotes: 1

Views: 547

Answers (1)

Nick Kovalsky
Nick Kovalsky

Reputation: 6452

Like they said you need to draw the bitmap first then draw antialiased circle over it. In your resulting image the non-antialiased bitmap is drawn over the circle.

Upvotes: 1

Related Questions