XAMARIN ANDROID:抗锯齿问题
XAMARIN ANDROID: Anti-Aliasing issue
我们创建了一种方法,可以从图像中切割出一个圆,然后用边框显示它。问题是,即使在 "true" 上设置了抗锯齿,它看起来像这样:
你可以清楚地看到,圆形图像非常像素化。这是我们用来调试的三星 S6 的屏幕截图。
这是有问题的代码:
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;
}
任何人都可以暗示我们朝着正确的方向前进吗?那太棒了:)
谢谢!
就像他们说的那样,您需要先绘制位图,然后在其上绘制抗锯齿圆圈。在生成的图像中,非抗锯齿位图绘制在圆上。
我们创建了一种方法,可以从图像中切割出一个圆,然后用边框显示它。问题是,即使在 "true" 上设置了抗锯齿,它看起来像这样:
你可以清楚地看到,圆形图像非常像素化。这是我们用来调试的三星 S6 的屏幕截图。
这是有问题的代码:
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;
}
任何人都可以暗示我们朝着正确的方向前进吗?那太棒了:)
谢谢!
就像他们说的那样,您需要先绘制位图,然后在其上绘制抗锯齿圆圈。在生成的图像中,非抗锯齿位图绘制在圆上。