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


C# Bitmap.LockImage方法代码示例

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


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

示例1: Generate

 /// <summary>
 /// Generates a cellular texture image
 /// </summary>
 /// <param name="Width">Width</param>
 /// <param name="Height">Height</param>
 /// <param name="NumberOfPoints">Number of points</param>
 /// <param name="Seed">Random seed</param>
 /// <returns>Returns an image of a cellular texture</returns>
 public static Bitmap Generate(int Width, int Height, int NumberOfPoints, int Seed)
 {
     float[,] DistanceBuffer = new float[Width, Height];
     float MinimumDistance = float.MaxValue;
     float MaxDistance = float.MinValue;
     CellularMap Map = new CellularMap(Seed, Width, Height, NumberOfPoints);
     MaxDistance = Map.MaxDistance;
     MinimumDistance = Map.MinDistance;
     DistanceBuffer = Map.Distances;
     Bitmap ReturnValue = new Bitmap(Width, Height);
     BitmapData ImageData = ReturnValue.LockImage();
     int ImagePixelSize = ImageData.GetPixelSize();
     for (int x = 0; x < Width; ++x)
     {
         for (int y = 0; y < Height; ++y)
         {
             float Value = GetHeight(x, y, DistanceBuffer, MinimumDistance, MaxDistance);
             Value *= 255;
             int RGBValue = ((int)Value).Clamp(255, 0);
             ImageData.SetPixel(x, y, Color.FromArgb(RGBValue, RGBValue, RGBValue), ImagePixelSize);
         }
     }
     ReturnValue.UnlockImage(ImageData);
     return ReturnValue;
 }
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:33,代码来源:CellularTexture.cs

示例2: AddNoise

 /// <summary>
 /// adds noise to the image
 /// </summary>
 /// <param name="OriginalImage">Image to add noise to</param>
 /// <param name="FileName">Location to save the image to (optional)</param>
 /// <param name="Amount">Amount of noise to add (defaults to 10)</param>
 /// <returns>New image object with the noise added</returns>
 public static Bitmap AddNoise(this Bitmap OriginalImage, int Amount = 10, string FileName = "")
 {
     OriginalImage.ThrowIfNull("OriginalImage");
     ImageFormat FormatUsing = FileName.GetImageFormat();
     Bitmap NewBitmap = new Bitmap(OriginalImage.Width, OriginalImage.Height);
     BitmapData NewData = NewBitmap.LockImage();
     BitmapData OldData = OriginalImage.LockImage();
     int NewPixelSize = NewData.GetPixelSize();
     int OldPixelSize = OldData.GetPixelSize();
     int Height = NewBitmap.Height;
     int Width = NewBitmap.Width;
     Parallel.For(0, Width, x =>
     {
         for (int y = 0; y < Height; ++y)
         {
             Color CurrentPixel = OldData.GetPixel(x, y, OldPixelSize);
             int R = CurrentPixel.R + Random.Random.ThreadSafeNext(-Amount, Amount + 1);
             int G = CurrentPixel.G + Random.Random.ThreadSafeNext(-Amount, Amount + 1);
             int B = CurrentPixel.B + Random.Random.ThreadSafeNext(-Amount, Amount + 1);
             R = R.Clamp(255, 0);
             G = G.Clamp(255, 0);
             B = B.Clamp(255, 0);
             Color TempValue = Color.FromArgb(R, G, B);
             NewData.SetPixel(x, y, TempValue, NewPixelSize);
         }
     });
     NewBitmap.UnlockImage(NewData);
     OriginalImage.UnlockImage(OldData);
     if (!string.IsNullOrEmpty(FileName))
         NewBitmap.Save(FileName, FormatUsing);
     return NewBitmap;
 }
开发者ID:MarkWalls,项目名称:Craig-s-Utility-Library,代码行数:39,代码来源:BitmapExtensions.cs

示例3: Generate

 /// <summary>
 /// Generates a number of faults, returning an image
 /// </summary>
 /// <param name="Width">Width of the resulting image</param>
 /// <param name="Height">Height of the resulting image</param>
 /// <param name="NumberFaults">Number of faults</param>
 /// <param name="Seed">Random seed</param>
 /// <returns>An image from the resulting faults</returns>
 public static Bitmap Generate(int Width,int Height,int NumberFaults,int Seed)
 {
     float[,] Heights = new float[Width, Height];
     float IncreaseVal = 0.1f;
     System.Random Generator = new System.Random(Seed);
     for (int x = 0; x < NumberFaults; ++x)
     {
         IncreaseVal = GenerateFault(Width, Height, NumberFaults, Heights, IncreaseVal, Generator);
     }
     Bitmap ReturnValue = new Bitmap(Width, Height);
     BitmapData ImageData = ReturnValue.LockImage();
     int ImagePixelSize = ImageData.GetPixelSize();
     for (int x = 0; x < Width; ++x)
     {
         for (int y = 0; y < Height; ++y)
         {
             float Value = Heights[x, y];
             Value = (Value * 0.5f) + 0.5f;
             Value *= 255;
             int RGBValue = ((int)Value).Clamp(255, 0);
             ImageData.SetPixel(x, y, Color.FromArgb(RGBValue, RGBValue, RGBValue), ImagePixelSize);
         }
     }
     ReturnValue.UnlockImage(ImageData);
     return ReturnValue;
 }
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:34,代码来源:FaultFormation.cs

示例4: AddNoise

 /// <summary>
 /// adds noise to the image
 /// </summary>
 /// <param name="OriginalImage">Image to add noise to</param>
 /// <param name="FileName">Location to save the image to (optional)</param>
 /// <param name="Amount">Amount of noise to add (defaults to 10)</param>
 /// <returns>New image object with the noise added</returns>
 public static Bitmap AddNoise(this Bitmap OriginalImage, int Amount = 10, string FileName = "")
 {
     if (OriginalImage == null)
         throw new ArgumentNullException("OriginalImage");
     ImageFormat FormatUsing = FileName.GetImageFormat();
     Bitmap NewBitmap = new Bitmap(OriginalImage.Width, OriginalImage.Height);
     BitmapData NewData = NewBitmap.LockImage();
     BitmapData OldData = OriginalImage.LockImage();
     int NewPixelSize = NewData.GetPixelSize();
     int OldPixelSize = OldData.GetPixelSize();
     Random.Random TempRandom = new Random.Random();
     for (int x = 0; x < NewBitmap.Width; ++x)
     {
         for (int y = 0; y < NewBitmap.Height; ++y)
         {
             Color CurrentPixel = OldData.GetPixel(x, y, OldPixelSize);
             int R = CurrentPixel.R + TempRandom.Next(-Amount, Amount + 1);
             int G = CurrentPixel.G + TempRandom.Next(-Amount, Amount + 1);
             int B = CurrentPixel.B + TempRandom.Next(-Amount, Amount + 1);
             R = R > 255 ? 255 : R;
             R = R < 0 ? 0 : R;
             G = G > 255 ? 255 : G;
             G = G < 0 ? 0 : G;
             B = B > 255 ? 255 : B;
             B = B < 0 ? 0 : B;
             Color TempValue = Color.FromArgb(R, G, B);
             NewData.SetPixel(x, y, TempValue, NewPixelSize);
         }
     }
     NewBitmap.UnlockImage(NewData);
     OriginalImage.UnlockImage(OldData);
     if (!string.IsNullOrEmpty(FileName))
         NewBitmap.Save(FileName, FormatUsing);
     return NewBitmap;
 }
开发者ID:JKLFA,项目名称:Craig-s-Utility-Library,代码行数:42,代码来源:BitmapExtensions.cs

示例5: Generate

 /// <summary>
 /// Generates perlin noise
 /// </summary>
 /// <param name="Width">Width of the resulting image</param>
 /// <param name="Height">Height of the resulting image</param>
 /// <param name="MaxRGBValue">MaxRGBValue</param>
 /// <param name="MinRGBValue">MinRGBValue</param>
 /// <param name="Frequency">Frequency</param>
 /// <param name="Amplitude">Amplitude</param>
 /// <param name="Persistance">Persistance</param>
 /// <param name="Octaves">Octaves</param>
 /// <param name="Seed">Random seed</param>
 /// <returns>An image containing perlin noise</returns>
 public static Bitmap Generate(int Width, int Height, int MaxRGBValue, int MinRGBValue,
     float Frequency, float Amplitude, float Persistance, int Octaves, int Seed)
 {
     Bitmap ReturnValue = new Bitmap(Width, Height);
     BitmapData ImageData = ReturnValue.LockImage();
     int ImagePixelSize = ImageData.GetPixelSize();
     float[,] Noise = GenerateNoise(Seed, Width, Height);
     for (int x = 0; x < Width; ++x)
     {
         for (int y = 0; y < Height; ++y)
         {
             float Value = GetValue(x, y, Width, Height, Frequency, Amplitude, Persistance, Octaves, Noise);
             Value = (Value * 0.5f) + 0.5f;
             Value *= 255;
             int RGBValue = ((int)Value).Clamp(MaxRGBValue, MinRGBValue);
             ImageData.SetPixel(x, y, Color.FromArgb(RGBValue, RGBValue, RGBValue), ImagePixelSize);
         }
     }
     ReturnValue.UnlockImage(ImageData);
     return ReturnValue;
 }
开发者ID:MarkWalls,项目名称:Craig-s-Utility-Library,代码行数:34,代码来源:PerlinNoise.cs

示例6: Equalize

 public static Bitmap Equalize(this Bitmap OriginalImage, string FileName = "")
 {
     OriginalImage.ThrowIfNull("OriginalImage");
     ImageFormat FormatUsing = FileName.GetImageFormat();
     Bitmap NewBitmap = new Bitmap(OriginalImage.Width, OriginalImage.Height);
     RGBHistogram TempHistogram = new RGBHistogram(OriginalImage);
     TempHistogram.Equalize();
     BitmapData NewData = NewBitmap.LockImage();
     BitmapData OldData = OriginalImage.LockImage();
     int NewPixelSize = NewData.GetPixelSize();
     int OldPixelSize = OldData.GetPixelSize();
     int Width = NewBitmap.Width;
     int Height = NewBitmap.Height;
     Parallel.For(0, Width, x =>
     {
         for (int y = 0; y < Height; ++y)
         {
             Color Current = OldData.GetPixel(x, y, OldPixelSize);
             int NewR = (int)TempHistogram.R[Current.R];
             int NewG = (int)TempHistogram.G[Current.G];
             int NewB = (int)TempHistogram.B[Current.B];
             NewR = NewR.Clamp(255, 0);
             NewG = NewG.Clamp(255, 0);
             NewB = NewB.Clamp(255, 0);
             NewData.SetPixel(x, y, Color.FromArgb(NewR, NewG, NewB), NewPixelSize);
         }
     });
     NewBitmap.UnlockImage(NewData);
     OriginalImage.UnlockImage(OldData);
     if (!string.IsNullOrEmpty(FileName))
         NewBitmap.Save(FileName, FormatUsing);
     return NewBitmap;
 }
开发者ID:Adilson,项目名称:Craig-s-Utility-Library,代码行数:33,代码来源:BitmapExtensions.cs

示例7: Jitter

        public static Bitmap Jitter(this Bitmap OriginalImage, int MaxJitter = 5, string FileName = "")
        {
            OriginalImage.ThrowIfNull("OriginalImage");
            ImageFormat FormatUsing = FileName.GetImageFormat();
            Bitmap NewBitmap = new Bitmap(OriginalImage, OriginalImage.Width, OriginalImage.Height);
            BitmapData NewData = NewBitmap.LockImage();
            BitmapData OldData = OriginalImage.LockImage();
            int NewPixelSize = NewData.GetPixelSize();
            int OldPixelSize = OldData.GetPixelSize();
            int Width = NewBitmap.Width;
            int Height = NewBitmap.Height;
            Parallel.For(0, Width, x =>
            {
                for (int y = 0; y < Height; ++y)
                {
                    int NewX = Random.Random.ThreadSafeNext(-MaxJitter, MaxJitter);
                    int NewY = Random.Random.ThreadSafeNext(-MaxJitter, MaxJitter);
                    NewX += x;
                    NewY += y;
                    NewX = NewX.Clamp(Width - 1, 0);
                    NewY = NewY.Clamp(Height - 1, 0);

                    NewData.SetPixel(x, y, OldData.GetPixel(NewX, NewY, OldPixelSize), NewPixelSize);
                }
            });
            NewBitmap.UnlockImage(NewData);
            OriginalImage.UnlockImage(OldData);
            if (!string.IsNullOrEmpty(FileName))
                NewBitmap.Save(FileName, FormatUsing);
            return NewBitmap;
        }
开发者ID:Adilson,项目名称:Craig-s-Utility-Library,代码行数:31,代码来源:BitmapExtensions.cs

示例8: AdjustGamma

        public static Bitmap AdjustGamma(Bitmap OriginalImage, float Value)
        {
            Bitmap NewBitmap = new Bitmap(OriginalImage.Width, OriginalImage.Height);
            BitmapData NewData = NewBitmap.LockImage();//Image.LockImage(NewBitmap);
            BitmapData OldData = OriginalImage.LockImage();//Image.LockImage(OriginalImage);
            int NewPixelSize = NewData.GetPixelSize();//Image.GetPixelSize(NewData);
            int OldPixelSize = OldData.GetPixelSize();//Image.GetPixelSize(OldData);

            int[] RedRamp = new int[256];
            int[] GreenRamp = new int[256];
            int[] BlueRamp = new int[256];
            for (int x = 0; x < 256; ++x)
            {
                RedRamp[x] = Clamp((int)((255.0 * System.Math.Pow(x / 255.0, 1.0 / Value)) + 0.5), 255, 0);
                GreenRamp[x] = Clamp((int)((255.0 * System.Math.Pow(x / 255.0, 1.0 / Value)) + 0.5), 255, 0);
                BlueRamp[x] = Clamp((int)((255.0 * System.Math.Pow(x / 255.0, 1.0 / Value)) + 0.5), 255, 0);
            }

            for (int x = 0; x < NewBitmap.Width; ++x)
            {
                for (int y = 0; y < NewBitmap.Height; ++y)
                {
                    Color Pixel = OldData.GetPixel(x, y, OldPixelSize);//Image.GetPixel(OldData, x, y, OldPixelSize);
                    int Red = RedRamp[Pixel.R];
                    int Green = GreenRamp[Pixel.G];
                    int Blue = BlueRamp[Pixel.B];
                    NewData.SetPixel(x, y, Color.FromArgb(Red, Green, Blue), NewPixelSize);//Image.SetPixel(NewData, x, y, Color.FromArgb(Red, Green, Blue), NewPixelSize);
                }
            }

            NewBitmap.UnlockImage(NewData);//Image.UnlockImage(NewBitmap, NewData);
            OriginalImage.UnlockImage(OldData);//Image.UnlockImage(OriginalImage, OldData);
            return NewBitmap;
        }
开发者ID:MFathirIrhas,项目名称:TugasAkhir1,代码行数:34,代码来源:ImageAttack.cs

示例9: SinWave

 public static Bitmap SinWave(this Bitmap OriginalImage, float Amplitude, float Frequency, bool XDirection, bool YDirection, string FileName = "")
 {
     OriginalImage.ThrowIfNull("OriginalImage");
     ImageFormat FormatUsing = FileName.GetImageFormat();
     Bitmap NewBitmap = new Bitmap(OriginalImage.Width, OriginalImage.Height);
     BitmapData NewData = NewBitmap.LockImage();
     BitmapData OldData = OriginalImage.LockImage();
     int NewPixelSize = NewData.GetPixelSize();
     int OldPixelSize = OldData.GetPixelSize();
     int Width = NewBitmap.Width;
     int Height = NewBitmap.Height;
     Parallel.For(0, Width, x =>
     {
         for (int y = 0; y < Height; ++y)
         {
             double Value1 = 0;
             double Value2 = 0;
             if (YDirection)
                 Value1 = System.Math.Sin(((x * Frequency) * System.Math.PI) / 180.0d) * Amplitude;
             if (XDirection)
                 Value2 = System.Math.Sin(((y * Frequency) * System.Math.PI) / 180.0d) * Amplitude;
             Value1 = y - (int)Value1;
             Value2 = x - (int)Value2;
             while (Value1 < 0)
                 Value1 += Height;
             while (Value2 < 0)
                 Value2 += Width;
             while (Value1 >= Height)
                 Value1 -= Height;
             while (Value2 >= Width)
                 Value2 -= Width;
             NewData.SetPixel(x, y,
                 OldData.GetPixel((int)Value2, (int)Value1, OldPixelSize),
                 NewPixelSize);
         }
     });
     NewBitmap.UnlockImage(NewData);
     OriginalImage.UnlockImage(OldData);
     if (!string.IsNullOrEmpty(FileName))
         NewBitmap.Save(FileName, FormatUsing);
     return NewBitmap;
 }
开发者ID:Adilson,项目名称:Craig-s-Utility-Library,代码行数:42,代码来源:BitmapExtensions.cs

示例10: 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

示例11: NormalMap

 public static Bitmap NormalMap(this Bitmap ImageUsing,bool InvertX=false,bool InvertY=false)
 {
     ImageUsing.ThrowIfNull("ImageUsing");
     using (Bitmap TempImageX = ImageUsing.BumpMap(Direction.LeftRight,InvertX))
     {
         using (Bitmap TempImageY = ImageUsing.BumpMap(Direction.TopBottom, InvertY))
         {
             Bitmap ReturnImage = new Bitmap(TempImageX.Width, TempImageX.Height);
             BitmapData TempImageXData = TempImageX.LockImage();
             BitmapData TempImageYData = TempImageY.LockImage();
             BitmapData ReturnImageData = ReturnImage.LockImage();
             int TempImageXPixelSize = TempImageXData.GetPixelSize();
             int TempImageYPixelSize = TempImageYData.GetPixelSize();
             int ReturnImagePixelSize = ReturnImageData.GetPixelSize();
             int Width = TempImageX.Width;
             int Height = TempImageX.Height;
             Parallel.For(0, Height, y =>
             {
                 Math.Vector3 TempVector = new Utilities.Math.Vector3(0.0, 0.0, 0.0);
                 for (int x = 0; x < Width; ++x)
                 {
                     Color TempPixelX = TempImageXData.GetPixel(x, y, TempImageXPixelSize);
                     Color TempPixelY = TempImageYData.GetPixel(x, y, TempImageYPixelSize);
                     TempVector.X = (double)(TempPixelX.R) / 255.0;
                     TempVector.Y = (double)(TempPixelY.R) / 255.0;
                     TempVector.Z = 1.0;
                     TempVector.Normalize();
                     TempVector.X = ((TempVector.X + 1.0) / 2.0) * 255.0;
                     TempVector.Y = ((TempVector.Y + 1.0) / 2.0) * 255.0;
                     TempVector.Z = ((TempVector.Z + 1.0) / 2.0) * 255.0;
                     ReturnImageData.SetPixel(x, y,
                         Color.FromArgb((int)TempVector.X,
                             (int)TempVector.Y,
                             (int)TempVector.Z),
                         ReturnImagePixelSize);
                 }
             });
             TempImageX.UnlockImage(TempImageXData);
             TempImageY.UnlockImage(TempImageYData);
             ReturnImage.UnlockImage(ReturnImageData);
             return ReturnImage;
         }
     }
 }
开发者ID:Adilson,项目名称:Craig-s-Utility-Library,代码行数:44,代码来源:BitmapExtensions.cs

示例12: Turbulence

 public static Bitmap Turbulence(this Bitmap OriginalImage, int Roughness = 8, float Power = 5.0f, int Seed = 25123864, string FileName = "")
 {
     OriginalImage.ThrowIfNull("OriginalImage");
     ImageFormat FormatUsing = FileName.GetImageFormat();
     int Width = OriginalImage.Width;
     int Height = OriginalImage.Height;
     BitmapData OriginalData = OriginalImage.LockImage();
     int OriginalPixelSize = OriginalData.GetPixelSize();
     Bitmap NewBitmap = new Bitmap(Width, Height);
     BitmapData ReturnData = NewBitmap.LockImage();
     int ReturnPixelSize = ReturnData.GetPixelSize();
     using (Bitmap XNoise = PerlinNoise.Generate(Width, Height, 255, 0, 0.0625f, 1.0f, 0.5f, Roughness, Seed))
     {
         BitmapData XNoiseData = XNoise.LockImage();
         int XNoisePixelSize = XNoiseData.GetPixelSize();
         using (Bitmap YNoise = PerlinNoise.Generate(Width, Height, 255, 0, 0.0625f, 1.0f, 0.5f, Roughness, Seed * 2))
         {
             BitmapData YNoiseData = YNoise.LockImage();
             int YNoisePixelSize = YNoiseData.GetPixelSize();
             Parallel.For(0, Height, y =>
             {
                 for (int x = 0; x < Width; ++x)
                 {
                     float XDistortion = x + (GetHeight(x, y, XNoiseData, XNoisePixelSize) * Power);
                     float YDistortion = y + (GetHeight(x, y, YNoiseData, YNoisePixelSize) * Power);
                     int X1 = ((int)XDistortion).Clamp(Width - 1, 0);
                     int Y1 = ((int)YDistortion).Clamp(Height - 1, 0);
                     ReturnData.SetPixel(x, y, OriginalData.GetPixel(X1, Y1, OriginalPixelSize), ReturnPixelSize);
                 }
             });
             YNoise.UnlockImage(YNoiseData);
         }
         XNoise.UnlockImage(XNoiseData);
     }
     NewBitmap.UnlockImage(ReturnData);
     UnlockImage(OriginalImage, OriginalData);
     if (!string.IsNullOrEmpty(FileName))
         NewBitmap.Save(FileName, FormatUsing);
     return NewBitmap;
 }
开发者ID:Adilson,项目名称:Craig-s-Utility-Library,代码行数:40,代码来源:BitmapExtensions.cs

示例13: LoadImage

 /// <summary>
 /// Loads an image
 /// </summary>
 /// <param name="ImageUsing">Image to load</param>
 public virtual void LoadImage(Bitmap ImageUsing)
 {
     ImageUsing.ThrowIfNull("ImageUsing");
     BitmapData OldData = ImageUsing.LockImage();
     int PixelSize = OldData.GetPixelSize();
     Width = ImageUsing.Width;
     Height = ImageUsing.Height;
     R.Clear();
     G.Clear();
     B.Clear();
     for (int x = 0; x < Width; ++x)
     {
         for (int y = 0; y < Height; ++y)
         {
             Color TempColor = OldData.GetPixel(x, y, PixelSize);
             ++R[(int)TempColor.R];
             ++G[(int)TempColor.G];
             ++B[(int)TempColor.B];
         }
     }
     ImageUsing.UnlockImage(OldData);
 }
开发者ID:Adilson,项目名称:Craig-s-Utility-Library,代码行数:26,代码来源:RGBHistogram.cs

示例14: StretchContrast

 public static Bitmap StretchContrast(this Bitmap OriginalImage, string FileName = "")
 {
     OriginalImage.ThrowIfNull("OriginalImage");
     ImageFormat FormatUsing = FileName.GetImageFormat();
     Bitmap NewBitmap = new Bitmap(OriginalImage.Width, OriginalImage.Height);
     BitmapData NewData = NewBitmap.LockImage();
     BitmapData OldData = OriginalImage.LockImage();
     int NewPixelSize = NewData.GetPixelSize();
     int OldPixelSize = OldData.GetPixelSize();
     Color MinValue;
     Color MaxValue;
     GetMinMaxPixel(out MinValue, out MaxValue, OldData, OldPixelSize);
     int Width = NewBitmap.Width;
     int Height = NewBitmap.Height;
     Parallel.For(0, Width, x =>
     {
         for (int y = 0; y < Height; ++y)
         {
             Color CurrentPixel = OldData.GetPixel(x, y, OldPixelSize);
             Color TempValue = Color.FromArgb(Map(CurrentPixel.R, MinValue.R, MaxValue.R),
                 Map(CurrentPixel.G, MinValue.G, MaxValue.G),
                 Map(CurrentPixel.B, MinValue.B, MaxValue.B));
             NewData.SetPixel(x, y, TempValue, NewPixelSize);
         }
     });
     NewBitmap.UnlockImage(NewData);
     OriginalImage.UnlockImage(OldData);
     if (!string.IsNullOrEmpty(FileName))
         NewBitmap.Save(FileName, FormatUsing);
     return NewBitmap;
 }
开发者ID:Adilson,项目名称:Craig-s-Utility-Library,代码行数:31,代码来源:BitmapExtensions.cs

示例15: Threshold

 public static Bitmap Threshold(this Bitmap OriginalImage, float Threshold = 0.5f, string FileName = "")
 {
     OriginalImage.ThrowIfNull("OriginalImage");
     ImageFormat FormatUsing = FileName.GetImageFormat();
     Bitmap NewBitmap = new Bitmap(OriginalImage.Width, OriginalImage.Height);
     BitmapData NewData = NewBitmap.LockImage();
     BitmapData OldData = OriginalImage.LockImage();
     int NewPixelSize = NewData.GetPixelSize();
     int OldPixelSize = OldData.GetPixelSize();
     int Width = NewBitmap.Width;
     int Height = NewBitmap.Height;
     Parallel.For(0, Width, x =>
     {
         for (int y = 0; y < Height; ++y)
         {
             Color TempColor = OldData.GetPixel(x, y, OldPixelSize);
             if ((TempColor.R + TempColor.G + TempColor.B) / 755.0f > Threshold)
                 NewData.SetPixel(x, y, Color.White, NewPixelSize);
             else
                 NewData.SetPixel(x, y, Color.Black, NewPixelSize);
         }
     });
     NewBitmap.UnlockImage(NewData);
     OriginalImage.UnlockImage(OldData);
     if (!string.IsNullOrEmpty(FileName))
         NewBitmap.Save(FileName, FormatUsing);
     return NewBitmap;
 }
开发者ID:Adilson,项目名称:Craig-s-Utility-Library,代码行数:28,代码来源:BitmapExtensions.cs


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