本文整理汇总了C#中System.Drawing.Image.GetPixels方法的典型用法代码示例。如果您正苦于以下问题:C# Image.GetPixels方法的具体用法?C# Image.GetPixels怎么用?C# Image.GetPixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Image
的用法示例。
在下文中一共展示了Image.GetPixels方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyKernel
public void ApplyKernel(Image image, Kernel kernel)
{
int[,] currentPixels = image.GetPixels();
int[,] newPixels = new int[image.Size.Width, image.Size.Height];
//kernel information
int kernelWidth = kernel.kernelSize.Width;
int kernelHeight = kernel.kernelSize.Height;
int middelPixelIndexWidth = kernelWidth / 2;
int middelPixelIndexHeight = kernelHeight / 2;
//Loop through the image
for (int x = 0; x < image.Size.Width; x++)
{
for (int y = 0; y < image.Size.Height; y++)
{
newPixels[x, y] = currentPixels[x, y];//current quickfix untill the proper kernel-out-of-bounce-code is implemented. This line adds an initial value of the current pixel, based on the original image.
//Determin kernel's position, based on current pixel
int kernelStartPositionX = x - middelPixelIndexWidth;
int kernelStartPositionY = y - middelPixelIndexHeight;
//variable to store the new values that are being calculated
double ColourValue = 0;
//checks if the kernel isn't out of bounce
if (kernelStartPositionX < 0 || kernelStartPositionY < 0) continue;
if (kernelStartPositionX + kernel.kernelSize.Width > image.Size.Width || kernelStartPositionY + kernel.kernelSize.Height > image.Size.Height) continue;
//todo: change code so it will do something other then just 'not'changing the pixel, when the kernel is ou tof bounce
//Loop through the kernel
for (int k = 0; k < kernelWidth; k++)
{
for (int l = 0; l < kernelHeight; l++)
{
//Get the current kernel's position's color-value
int pixelColor = image.GetPixelColor(kernelStartPositionX + k, kernelStartPositionY + l);
ColourValue += (pixelColor * (kernel.GetValue(l, k) * kernel.multiplier)); //calculates the value that has to be added, based on the kernel value and multiplier
}
}
newPixels[x, y] = (int)(ColourValue); //sets new value
}
}
image.SetPixels(newPixels);
}
示例2: Fix
public static void Fix(Image image, int layers)
{
int[,] result = image.GetPixels();
for(int i = layers -1; i >= 0; i--) {
for(int x = i; x < image.Size.Width - i; x++)
{
result[x, i] = CalculateNewPixelValue(x, i, i, image);
result[x, image.Size.Height -1 - i] = CalculateNewPixelValue(x, image.Size.Height - 1 - i, i, image);
}
for (int y = i; y < image.Size.Height - i; y++)
{
result[i, y] = CalculateNewPixelValue(i, y, i, image);
result[image.Size.Width - 1 - i, y] = CalculateNewPixelValue(image.Size.Width - 1 - i, y, i, image);
}
image.SetPixels(result);
}
}