A
A
aeaeae12022-04-10 04:13:17
C++ / C#
aeaeae1, 2022-04-10 04:13:17

Why does an error occur when calling Bitmap?

I'm writing a program that shows a color when clicked.
I can't figure out why this error occurs.
Object reference does not point to an instance of an object.

[CSHARP]
    var rato = e as MouseEventArgs;

              Bitmap b = ((Bitmap)windowOriginal.Image);
          

int x = rato.X * b.Width / windowOriginal.ClientSize.Width;//Вот здесь выдает ошибку
            int y = rato.Y * b.Height / windowOriginal.ClientSize.Height;
            Color c = b.GetPixel(rato.X, rato.Y);
            var h = Math.Round(c.GetHue(), 0);
            h = (h * 255) / 360;
            var s = Math.Round(c.GetSaturation() * 255, 0);
            var v = Math.Round(c.GetBrightness() * 255, 0);


            listBox1.Text = "H:" + h + " S: " + s + " V: " + v;
            listBox1.Text = "R: " + c.R + " G: " + c.G + " B: " + c.B;
            MessageBox.Show("H:" + h + " S: " + s + " V: " + v);

[/CSHARP]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question