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?

  • Place on top of this PictureBox any Panel filled with a semi-transparent red color. - Alexander Petrov
  • it is easier to use panel instead of picturebox if you need a rectangle filled with one color - Andrei Khotko
  • You can try to change the color of the content pixel by pixel, only it is terribly slow and inefficient. - BlackWitcher

1 answer 1

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.