There is a blue square image embedded in the picturebox. Is it possible to make its color (or shade) red, without changing it to another image or changing the color of each pixel?
1 answer
It is possible to place a panel filled with a translucent color on top of the PictureBox .
To test, we create a new Windows Forms project, put the code in the form designer:
public Form1() { //InitializeComponent(); // Π‘ΠΎΠ·Π΄Π°ΡΠΌ ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΠ΅ - ΡΠΈΠ½ΠΈΠΉ ΠΊΠ²Π°Π΄ΡΠ°Ρ var bmp = new Bitmap(150, 150); var g = Graphics.FromImage(bmp); g.Clear(Color.Blue); var pictureBox = new PictureBox { Parent = this, Width = 200, Height = 200, BorderStyle = BorderStyle.FixedSingle }; pictureBox.Image = bmp; // Π‘ΠΎΠ·Π΄Π°ΡΠΌ ΠΏΠ°Π½Π΅Π»Ρ. ΠΠ±ΡΠ°ΡΠΈΡΠ΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅: Π΅Ρ ΡΠΎΠ΄ΠΈΡΠ΅Π»Ρ - pictureBox var panel = new Panel { Parent = pictureBox, BackColor = Color.FromArgb(100, Color.Red), //Dock = DockStyle.Fill Size = pictureBox.Image.Size }; } Color.FromArgb(100, Color.Red) - a color is created here with a transparency factor of 100 (maybe from 0 to 255; try playing with it).
If the picture occupies the entire pchchabox area, then the panel can be set with the Dock = DockStyle.Fill (we do not specify the size). Otherwise, we set the same dimensions as the image.
|
PictureBoxanyPanelfilled with a semi-transparent red color. - Alexander Petrovpanelinstead ofpictureboxif you need a rectangle filled with one color - Andrei Khotko