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


C# Image.SetPixelColor方法代码示例

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


在下文中一共展示了Image.SetPixelColor方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Apply

        public override void Apply(Image image)
        {
            int totalGrayValue = 0;//Start counter
            for (int x = 0; x < image.Size.Width; x++)
            {
                for (int y = 0; y < image.Size.Height; y++)
                {
                    totalGrayValue += image.GetPixelColor(x, y);
                }
            }
            <<<<<<< HEAD
            =======

            int AverageGrayValue = (totalGrayValue > 0) ? totalGrayValue / (Image.Size.Width * Image.Size.Height) : 0;
            >>>>>>> refs/remotes/origin/Koen-Edges

            int AverageGrayValue = (totalGrayValue > 0) ? totalGrayValue / (image.Size.Width * image.Size.Height) : 0;

            for (int x = 0; x < image.Size.Width; x++)
            {
                for (int y = 0; y < image.Size.Height; y++)
                {
                    int pixelColor = image.GetPixelColor(x, y);                         // Get the pixel color at coordinate (x,y)
                    //int threshold = 186;
                    int updatedColor = (pixelColor > AverageGrayValue) ? Image.White : Image.Black;          // black or white
                    image.SetPixelColor(x, y, updatedColor);                              // Set the new pixel color at coordinate (x,y)
                }
            }
        }
开发者ID:jianjia93,项目名称:ImageProcessing,代码行数:29,代码来源:NegativeThreshold.cs

示例2: Apply

 /// <summary>
 /// Turns the image into its negative
 /// </summary>
 /// <param name="image">Image that gets the operation applied to</param>
 public override void Apply(Image image)
 {
     for (int x = 0; x < image.Size.Width; x++)
     {
         for (int y = 0; y < image.Size.Height; y++)
         {
             image.SetPixelColor(x, y, (Image.TotalGrayValues - 1) - (image.GetPixelColor(x, y)));     //Inverse by subtracting the current pixel value of the max gray value
         }
     }
 }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:14,代码来源:Negative.cs

示例3: Apply

        /// <summary>
        /// Calculate Difference and return a new image that represents the differences
        /// </summary>
        /// <param name="img1">first image</param>
        /// <param name="img2">second image</param>
        /// <returns>a new images that represents the difference between the input images</returns>
        public static Image Apply(Image img1, Image img2)
        {
            Image newImg = new Image(img1.GetPixels(), img1.Size);

            for (int x = 0; x < newImg.Size.Width; x++)
            {
                for (int y = 0; y < newImg.Size.Height; y++)
                {
                    if (img1.GetPixelColor(x, y) == img2.GetPixelColor(x, y)) //If pixels are the same
                    {
                        newImg.SetPixelColor(x, y, Image.Black); //set a black pixel
                    }
                    else
                    {
                        newImg.SetPixelColor(x, y, Image.White); //else, set a white pixel
                    }
                }
            }
            return newImg;
        }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:26,代码来源:Difference.cs

示例4: ApplyBlackWhite

 /// <summary>
 /// Subtract the values from the second image from the first image. This method is used for black/white images.
 /// So all the black values from the second image will be subtracted from the first one.
 /// Read: Black = 1, White = 0; (This doesn't correspond with the actual values)
 /// </summary>
 /// <param name="Image"></param>
 /// <param name="Image2"></param>
 /// <returns></returns>
 public static Image ApplyBlackWhite(Image Image, Image Image2)
 {
     Image newImg = new Image(Image.GetPixels(), Image.Size);
     for (int x = 0; x < Image.Size.Width; x++)
     {
         for (int y = 0; y < Image.Size.Height; y++)
         {
             if (Image2.GetPixelColor(x, y) == Image.Black) newImg.SetPixelColor(x, y, Image.White);
         }
     }
     return newImg;
 }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:20,代码来源:Subtraction.cs

示例5: Apply

 public static Image Apply(Image Image, Image Image2)
 {
     for (int x = 0; x < Image.Size.Width; x++)
     {
         for (int y = 0; y < Image.Size.Height; y++)
         {
             if (Image.GetPixelColor(x, y) > Image2.GetPixelColor(x, y))
             {
                 Image.SetPixelColor(x,y,Image2.GetPixelColor(x, y));
             }
         }
     }
     return Image;
 }
开发者ID:jianjia93,项目名称:ImageProcessing,代码行数:14,代码来源:Minval.cs

示例6: Apply

 /// <summary>
 /// Merge two images together
 /// </summary>
 /// <param name="Image">Input image 1</param>
 /// <param name="Image2">Input image 2</param>
 /// <returns>New image, which contains the two input images merged</returns>
 public static Image Apply(Image Image, Image Image2)
 {
     Image newImg = new Image(Image.GetPixels(), Image.Size);
     for (int x = 0; x < Image.Size.Width; x++)
     {
         for (int y = 0; y < Image.Size.Height; y++)
         {
             int additive_value = (Image.GetPixelColor(x, y)+ Image2.GetPixelColor(x, y));
             additive_value = (int)((additive_value) / 2.0f);//This line will re-balance the values from [ 0 , 510 ], to [ 0 , 255 ]
             newImg.SetPixelColor(x, y, additive_value);
         }
     }
     return newImg;
 }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:20,代码来源:Addition.cs

示例7: Apply

 public static Image Apply(Image Image, Image Image2)
 {
     int additive_value = 0;
     for (int x = 0; x < Image.Size.Width; x++)
     {
         for (int y = 0; y < Image.Size.Height; y++)
         {
             additive_value = (Image.GetPixelColor(x, y)- Image2.GetPixelColor(x, y));
             if (additive_value < 0) additive_value = 0;
             Image.SetPixelColor(x, y, additive_value);
         }
     }
     return Image;
 }
开发者ID:jianjia93,项目名称:ImageProcessing,代码行数:14,代码来源:Subtraction.cs

示例8: Apply

 /// <summary>
 /// Applies XOR, returning a new image that only contains black pixels that are in both images
 /// </summary>
 /// <param name="Image">target image 1</param>
 /// <param name="Image2">target image 2</param>
 /// <returns>new image that contains the black pixels that are in both images</returns>
 public static Image Apply(Image Image, Image Image2)
 {
     Image newImg = new Image(Image.GetPixels(), Image.Size);
     for (int x = 0; x < Image.Size.Width; x++)
     {
         for (int y = 0; y < Image.Size.Height; y++)
         {
             bool img1 = (Image.GetPixelColor(x, y) == Image.Black);//if image 1 has a black pixel on this position
             bool img2 = (Image2.GetPixelColor(x, y) == Image.Black);//if image 2 has a black pixel on this position
             int result = (img1 || img2) ? Image.Black : Image.White;//if either one of the two booleans is true, draw black. Else draw white.
             newImg.SetPixelColor(x, y, result);
         }
     }
     return newImg;
 }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:21,代码来源:OR.cs

示例9: Apply

 /// <summary>
 /// Subtract the values of the second image from the first image. Normalise the image afterwards.
 /// </summary>
 public static Image Apply(Image Image, Image Image2)
 {
     Image newImg = new Image(Image.GetPixels(), Image.Size); //Todo: Shouln't we just make a new pixel array here, instead of copying the first image?
     for (int x = 0; x < Image.Size.Width; x++)
     {
         for (int y = 0; y < Image.Size.Height; y++)
         {
             int additive_value = (Image.GetPixelColor(x, y)- Image2.GetPixelColor(x, y));
             //if (additive_value < 0) additive_value = Image.Black;
             int highestValue = Image.White;
             additive_value = (int)((additive_value + highestValue) / 2.0f);//This line will re-balance the values from [ -225, 255 ], to [ 0 , 255 ]
             newImg.SetPixelColor(x, y, additive_value);
         }
     }
     return newImg;
 }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:19,代码来源:Subtraction.cs

示例10: Apply

        /// <summary>
        /// Apply this operation to the image
        /// </summary>
        /// <param name="image">Image that gets the operation applied to</param>
        public override void Apply(Image image)
        {
            int totalGrayValue = 0;//Start counter
            for (int x = 0; x < image.Size.Width; x++)
            {
                for (int y = 0; y < image.Size.Height; y++)
                {
                    totalGrayValue += image.GetPixelColor(x, y);
                }
            }

            int AverageGrayValue = (totalGrayValue > 0) ? totalGrayValue / (image.Size.Width * image.Size.Height) : 0;

            for (int x = 0; x < image.Size.Width; x++)
            {
                for (int y = 0; y < image.Size.Height; y++)
                {
                    int pixelColor = image.GetPixelColor(x, y);                         // Get the pixel color at coordinate (x,y)
                    //AverageGrayValue = 210;
                    int updatedColor = (pixelColor > AverageGrayValue) ? Image.White : Image.Black;          // black or white
                    image.SetPixelColor(x, y, updatedColor);                              // Set the new pixel color at coordinate (x,y)
                }
            }
        }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:28,代码来源:NegativeThreshold.cs


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