當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。