-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColoredPictureBox.cs
49 lines (42 loc) · 1.24 KB
/
ColoredPictureBox.cs
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
using System.Drawing;
using System.Drawing.Imaging;
namespace VRCWMT;
public class ColoredPictureBox : PictureBox
{
private Color _overlayColor = Color.Transparent;
public Color OverlayColor
{
get
{
return _overlayColor;
}
set
{
_overlayColor = value;
Invalidate();
}
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
if (Image != null)
{
ImageAttributes imageAttributes = new ImageAttributes();
ColorMatrix colorMatrix = new ColorMatrix();
// Apply overlay color
if (_overlayColor != Color.Transparent)
{
colorMatrix.Matrix00 = ((_overlayColor.R / 255f)*2)-1;
colorMatrix.Matrix01 = ((_overlayColor.G / 255f) * 2) - 1;
colorMatrix.Matrix02 = ((_overlayColor.B / 255f) * 2) - 1;
}
imageAttributes.SetColorMatrix(colorMatrix);
pe.Graphics.DrawImage(
Image,
new Rectangle(0, 0, Width, Height),
0, 0, Image.Width, Image.Height,
GraphicsUnit.Pixel,
imageAttributes);
}
}
}