當前位置: 首頁>>代碼示例>>C#>>正文


C# Bitmap.BlackAndWhite方法代碼示例

本文整理匯總了C#中System.Drawing.Bitmap.BlackAndWhite方法的典型用法代碼示例。如果您正苦於以下問題:C# Bitmap.BlackAndWhite方法的具體用法?C# Bitmap.BlackAndWhite怎麽用?C# Bitmap.BlackAndWhite使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Drawing.Bitmap的用法示例。


在下文中一共展示了Bitmap.BlackAndWhite方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ConvertToASCII

        /// <summary>
        /// Converts an image to ASCII art
        /// </summary>
        /// <param name="Input">The image you wish to convert</param>
        /// <returns>A string containing the art</returns>
        public static string ConvertToASCII(Bitmap Input)
        {
            if (Input == null)
                throw new ArgumentNullException("Input");
            bool ShowLine = true;
            using (Bitmap TempImage = Input.BlackAndWhite())
            {
                BitmapData OldData = TempImage.LockImage();
                int OldPixelSize = OldData.GetPixelSize();
                StringBuilder Builder = new StringBuilder();
                for (int x = 0; x < TempImage.Height; ++x)
                {
                    for (int y = 0; y < TempImage.Width; ++y)
                    {
                        if (ShowLine)
                        {
                            Color CurrentPixel = OldData.GetPixel(y, x, OldPixelSize);
                            Builder.Append(_ASCIICharacters[((CurrentPixel.R * _ASCIICharacters.Length) / 255)]);
                        }

                    }
                    if (ShowLine)
                    {
                        Builder.Append(System.Environment.NewLine);
                        ShowLine = false;
                    }
                    else
                    {
                        ShowLine = true;
                    }
                }
                TempImage.UnlockImage(OldData);
                return Builder.ToString();
            }
        }
開發者ID:JKLFA,項目名稱:Craig-s-Utility-Library,代碼行數:40,代碼來源:ASCIIArt.cs

示例2: Colorize

 public void Colorize()
 {
     using (Bitmap TestObject = new Bitmap(@"..\..\Data\Image\Lenna.jpg"))
     {
         List<Color> Colors = new List<Color>();
         for (int x = 0; x < 256; ++x)
             Colors.Add(Color.FromArgb(255 - x, 0, x));
         using (Bitmap TestObject2 = TestObject.BlackAndWhite())
         {
             using (Bitmap Image = Assert.Do<Bitmap>(() => TestObject2.Colorize(Colors.ToArray(), @".\Testing\LennaColorize.jpg")))
             {
                 Assert.NotNull(Image);
             }
         }
     }
 }
開發者ID:gwilkinson,項目名稱:Craig-s-Utility-Library,代碼行數:16,代碼來源:BitmapExtensions.cs

示例3: Process

 /// <summary>
 /// Runs the motion detection algorithm
 /// </summary>
 /// <param name="NewImage">The "new" frame</param>
 /// <param name="OldImage">The "old" frame</param>
 /// <param name="Threshold">The threshold used to detect changes in the image</param>
 /// <param name="DetectionColor">Color to display changes in the images as</param>
 /// <returns>A bitmap indicating where changes between frames have occurred overlayed on top of the new image.</returns>
 public static Bitmap Process(Bitmap NewImage, Bitmap OldImage, int Threshold, Color DetectionColor)
 {
     if (NewImage == null)
         throw new ArgumentNullException("NewImage");
     if (OldImage == null)
         throw new ArgumentNullException("OldImage");
     if (DetectionColor == null)
         throw new ArgumentNullException("DetectionColor");
     using (Bitmap NewImage1 = NewImage.BlackAndWhite())
     {
         using (Bitmap OldImage1 = OldImage.BlackAndWhite())
         {
             using (Bitmap NewImage2 = NewImage1.SNNBlur(5))
             {
                 using (Bitmap OldImage2 = OldImage1.SNNBlur(5))
                 {
                     using (Bitmap OutputImage = new Bitmap(NewImage2, NewImage2.Width, NewImage2.Height))
                     {
                         using (Bitmap Overlay = new Bitmap(NewImage, NewImage.Width, NewImage.Height))
                         {
                             BitmapData NewImage2Data = NewImage2.LockImage();
                             int NewImage2PixelSize = NewImage2Data.GetPixelSize();
                             BitmapData OldImage2Data = OldImage2.LockImage();
                             int OldImage2PixelSize = OldImage2Data.GetPixelSize();
                             BitmapData OverlayData = Overlay.LockImage();
                             int OverlayPixelSize = OverlayData.GetPixelSize();
                             for (int x = 0; x < OutputImage.Width; ++x)
                             {
                                 for (int y = 0; y < OutputImage.Height; ++y)
                                 {
                                     Color NewPixel = NewImage2Data.GetPixel(x, y, NewImage2PixelSize);
                                     Color OldPixel = OldImage2Data.GetPixel(x, y, OldImage2PixelSize);
                                     if (System.Math.Pow((double)(NewPixel.R - OldPixel.R), 2.0) > Threshold)
                                     {
                                         OverlayData.SetPixel(x, y, Color.FromArgb(100, 0, 100), OverlayPixelSize);
                                     }
                                     else
                                     {
                                         OverlayData.SetPixel(x, y, Color.FromArgb(200, 0, 200), OverlayPixelSize);
                                     }
                                 }
                             }
                             Overlay.UnlockImage(OverlayData);
                             NewImage2.UnlockImage(NewImage2Data);
                             OldImage2.UnlockImage(OldImage2Data);
                             using (Bitmap Overlay2 = Overlay.EdgeDetection(25, DetectionColor))
                             {
                                 BitmapData Overlay2Data = Overlay2.LockImage();
                                 int Overlay2PixelSize = Overlay2Data.GetPixelSize();
                                 for (int x = 0; x < OutputImage.Width; ++x)
                                 {
                                     for (int y = 0; y < OutputImage.Height; ++y)
                                     {
                                         Color Pixel1 = Overlay2Data.GetPixel(x, y, Overlay2PixelSize);
                                         if (Pixel1.R != DetectionColor.R || Pixel1.G != DetectionColor.G || Pixel1.B != DetectionColor.B)
                                         {
                                             Overlay2Data.SetPixel(x, y, Color.FromArgb(200, 0, 200), Overlay2PixelSize);
                                         }
                                     }
                                 }
                                 Overlay2.UnlockImage(Overlay2Data);
                                 return OutputImage.Watermark(Overlay2, 1.0f, 0, 0, Color.FromArgb(200, 0, 200));
                             }
                         }
                     }
                 }
             }
         }
     }
 }
開發者ID:JKLFA,項目名稱:Craig-s-Utility-Library,代碼行數:78,代碼來源:MotionDetection.cs

示例4: BlackAndWhite

 public void BlackAndWhite()
 {
     using (Bitmap TestObject = new Bitmap(@"..\..\Data\Image\Lenna.jpg"))
     {
         using (Bitmap Image = Assert.Do<Bitmap>(() => TestObject.BlackAndWhite(@".\Testing\LennaBlackAndWhite.jpg")))
         {
             Assert.NotNull(Image);
         }
     }
 }
開發者ID:gwilkinson,項目名稱:Craig-s-Utility-Library,代碼行數:10,代碼來源:BitmapExtensions.cs

示例5: MotionDetection

 /// <summary>
 /// Runs a simplistic motion detection algorithm
 /// </summary>
 /// <param name="NewImage">The "new" frame</param>
 /// <param name="OldImage">The "old" frame</param>
 /// <param name="Threshold">The threshold used to detect changes in the image</param>
 /// <param name="DetectionColor">Color to display changes in the images as</param>
 /// <returns>A bitmap indicating where changes between frames have occurred overlayed on top of the new image.</returns>
 public static Bitmap MotionDetection(this Bitmap NewImage, Bitmap OldImage, int Threshold, Color DetectionColor)
 {
     NewImage.ThrowIfNull("NewImage");
     OldImage.ThrowIfNull("OldImage");
     DetectionColor.ThrowIfNull("DetectionColor");
     using (Bitmap NewImage1 = NewImage.BlackAndWhite())
     {
         using (Bitmap OldImage1 = OldImage.BlackAndWhite())
         {
             using (Bitmap NewImage2 = NewImage1.SNNBlur(5))
             {
                 using (Bitmap OldImage2 = OldImage1.SNNBlur(5))
                 {
                     using (Bitmap OutputImage = new Bitmap(NewImage2, NewImage2.Width, NewImage2.Height))
                     {
                         using (Bitmap Overlay = new Bitmap(NewImage, NewImage.Width, NewImage.Height))
                         {
                             BitmapData NewImage2Data = NewImage2.LockImage();
                             int NewImage2PixelSize = NewImage2Data.GetPixelSize();
                             BitmapData OldImage2Data = OldImage2.LockImage();
                             int OldImage2PixelSize = OldImage2Data.GetPixelSize();
                             BitmapData OverlayData = Overlay.LockImage();
                             int OverlayPixelSize = OverlayData.GetPixelSize();
                             int Width = OutputImage.Width;
                             int Height = OutputImage.Height;
                             Parallel.For(0, Width, x =>
                             {
                                 for (int y = 0; y < Height; ++y)
                                 {
                                     Color NewPixel = NewImage2Data.GetPixel(x, y, NewImage2PixelSize);
                                     Color OldPixel = OldImage2Data.GetPixel(x, y, OldImage2PixelSize);
                                     if (System.Math.Pow((double)(NewPixel.R - OldPixel.R), 2.0) > Threshold)
                                     {
                                         OverlayData.SetPixel(x, y, Color.FromArgb(100, 0, 100), OverlayPixelSize);
                                     }
                                     else
                                     {
                                         OverlayData.SetPixel(x, y, Color.FromArgb(200, 0, 200), OverlayPixelSize);
                                     }
                                 }
                             });
                             Overlay.UnlockImage(OverlayData);
                             NewImage2.UnlockImage(NewImage2Data);
                             OldImage2.UnlockImage(OldImage2Data);
                             using (Bitmap Overlay2 = Overlay.EdgeDetection(25, DetectionColor))
                             {
                                 BitmapData Overlay2Data = Overlay2.LockImage();
                                 int Overlay2PixelSize = Overlay2Data.GetPixelSize();
                                 Width = OutputImage.Width;
                                 Height = OutputImage.Height;
                                 Parallel.For(0, Width, x =>
                                 {
                                     for (int y = 0; y < Height; ++y)
                                     {
                                         Color Pixel1 = Overlay2Data.GetPixel(x, y, Overlay2PixelSize);
                                         if (Pixel1.R != DetectionColor.R || Pixel1.G != DetectionColor.G || Pixel1.B != DetectionColor.B)
                                         {
                                             Overlay2Data.SetPixel(x, y, Color.FromArgb(200, 0, 200), Overlay2PixelSize);
                                         }
                                     }
                                 });
                                 Overlay2.UnlockImage(Overlay2Data);
                                 return OutputImage.Watermark(Overlay2, 1.0f, 0, 0, Color.FromArgb(200, 0, 200));
                             }
                         }
                     }
                 }
             }
         }
     }
 }
開發者ID:Adilson,項目名稱:Craig-s-Utility-Library,代碼行數:79,代碼來源:BitmapExtensions.cs


注:本文中的System.Drawing.Bitmap.BlackAndWhite方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。