tangxu
2024-10-16 56b9a880c8def4c0fc06f89919157fa238beeeb4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#region Imports
 
using System.Drawing;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Extension.Crown
{
    #region BitmapExtensionsExtension
 
    internal static class BitmapExtensions
    {
        internal static Bitmap SetColor(this Bitmap bitmap, Color color)
        {
            Bitmap newBitmap = new(bitmap.Width, bitmap.Height);
            for (int i = 0; i < bitmap.Width; i++)
            {
                for (int j = 0; j < bitmap.Height; j++)
                {
                    Color pixel = bitmap.GetPixel(i, j);
                    if (pixel.A > 0)
                    {
                        newBitmap.SetPixel(i, j, color);
                    }
                }
            }
            return newBitmap;
        }
 
        internal static Bitmap ChangeColor(this Bitmap bitmap, Color oldColor, Color newColor)
        {
            Bitmap newBitmap = new(bitmap.Width, bitmap.Height);
            for (int i = 0; i < bitmap.Width; i++)
            {
                for (int j = 0; j < bitmap.Height; j++)
                {
                    Color pixel = bitmap.GetPixel(i, j);
                    if (pixel == oldColor)
                    {
                        newBitmap.SetPixel(i, j, newColor);
                    }
                }
            }
            return newBitmap;
        }
    }
 
    #endregion
}