是什么在C#.NET一个很好的像素化的算法? [英] What's a good pixelation algorithm in C# .NET?
本文介绍了是什么在C#.NET一个很好的像素化的算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是好的算法pixelating图像在C#.NET?
What is a good algorithm for pixelating an image in C# .NET?
推荐答案
一个简单的,但效率不高的解决方案是调整到一个更小的尺寸,然后调整回用像素复制。
A simple, yet unefficient solution would be to resize to a smaller size, then resize back using pixel duplication.
有一个更好的解决办法(伪code):
(时间为O(n),额外的空间(除了可变源图像):O(1))
A better solution would be (pseudo-code):
(Time O(n), Additional space (besides mutable source image): O(1))
// Pixelize in x axis (choose a whole k s.t. 1 <= k <= Width)
var sum = Pixel[0, 0];
for (y = 0; y < Height; y++)
{
for (x = 0; x < Width + 1; x++)
{
if (x % k == 0)
{
sum /= k;
for (xl = Max(0, x-k); xl < x; xl++)
Pixel[y, xl] = sum;
sum = 0;
}
if (x == Width)
break;
sum += Pixel[y, x];
}
}
// Now do the same in the y axis
// (make sure to keep y the outer loop - for better performance)
// If your image has more than one channel, then then Pixel should be a struct.
这篇关于是什么在C#.NET一个很好的像素化的算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文