我想在C#中编写自己的抗锯齿算法。我的照片只有两种颜色;黑与白。
在维基百科(https://en.wikipedia.org/wiki/Spatial_anti-aliasing)上,我找到了以下pseudecode:
Define function PlotAntiAliasedPoint ( number x, number y )
For roundedx = floor ( x ) to ceil ( x ) do
For roundedy = floor ( y ) to ceil ( y ) do
percent_x = 1 - abs ( x - roundedx )
percent_y = 1 - abs ( y - roundedy )
percent = percent_x * percent_y
DrawPixel ( coordinates roundedx, roundedy, color percent (range 0-1) )
如何在C#中实现这个伪代码?
答案 0 :(得分:0)
private void PlotAntiAliasedPoint(decimal x, decimal y)
{
for (var roundedx = Math.Floor(x); roundedx <= Math.Ceiling(x); roundedx++)
{
for (var roundedy = Math.Floor(y); roundedy <= Math.Ceiling(y); roundedy++)
{
var percent_x = 1 - Math.Abs(x - roundedx);
var percent_y = 1 - Math.Abs(y - roundedy);
var percent = percent_x*percent_y;
//DrawPixel(coordinates roundedx, roundedy, color percent(range 0 - 1))
}
}
}