How to get the RGB code of an entire image? The RGB code is to be displayed inside a textBox.in this form: RGB(148,149,155). If I change the brightness inside the image, the RGB code should also change inside. i cannot find RGB value of image and cannot see it in textbox
私が試したこと:
C#
private void textBox3_TextChanged(object sender, EventArgs e) { GetPixels(); } private Color[,] GetPixels() { Bitmap bmp = varas.ptvalrgb; Color[,] results = new Color[bmp.Width, bmp.Height]; for (int y = 0; y < bmp.Height; y++) { for (int x = 0; x < bmp.Width; x++) { results[x, y] = bmp.GetPixel(x, y); } } return results; } //brightness code private void trackBar1_Scroll(object sender, EventArgs e) { trackBar1.Value.ToString(); float value = trackBar1.Value * 0.01f; float[][] colorMatrixElements = { new float[] { 1, 0, 0, 0, 0 }, new float[] { 0, 1, 0, 0, 0 }, new float[] { 0, 0, 1, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { value, value, value, 0, 1 } }; ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements); ImageAttributes imageAttributes = new ImageAttributes(); imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); Image _img = varas.ptval;//varas.ptval is a bitmap image //PictureBox1.Image Graphics _g = default(Graphics); Bitmap bm_dest = new Bitmap(Convert.ToInt32(_img.Width), Convert.ToInt32(_img.Height)); _g = Graphics.FromImage(bm_dest); _g.DrawImage(_img, new Rectangle(0, 0, bm_dest.Width + 1, bm_dest.Height + 1), 0, 0, bm_dest.Width + 1, bm_dest.Height + 1, GraphicsUnit.Pixel, imageAttributes); LevelPicBox.Image = bm_dest; textBox1.Text = trackBar1.Value.ToString(); }
解決策 1
ここで答えをチェックしてください: https://stackoverflow.com/questions/10127871/how-can-i-read-image-pixels-values-as-rgb-into-2d-array[^]
コメント