当前位置: 首页>>代码示例>>C#>>正文


C# Image.SetPixels方法代码示例

本文整理汇总了C#中System.Drawing.Image.SetPixels方法的典型用法代码示例。如果您正苦于以下问题:C# Image.SetPixels方法的具体用法?C# Image.SetPixels怎么用?C# Image.SetPixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Image的用法示例。


在下文中一共展示了Image.SetPixels方法的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);
        }
开发者ID:jianjia93,项目名称:ImageProcessing,代码行数:48,代码来源:Operation.cs

示例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);
            }
        }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:18,代码来源:FixBorder.cs


注:本文中的System.Drawing.Image.SetPixels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。