Click here to Skip to main content
15,938,218 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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


What I have tried:

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();
		}
Posted
Updated 21-Dec-22 18:31pm
v2

 
Share this answer
 
Comments
Ridhdhi Vaghani 22-Dec-22 4:20am    
This code does not work. This is my image:- https://ibb.co/7SgXYXL. I mark the RGB value. I want the RGB value like this
Graeme_Grant 22-Dec-22 4:44am    
There is not enough information. Where does that value come from?
Ridhdhi Vaghani 22-Dec-22 5:45am    
When the brightness of the image is changed, it is to be printed in the label. The only thing to specify is where the RGB value comes from.
Graeme_Grant 22-Dec-22 5:48am    
That is what I am asking you. Where does it come from?
Ridhdhi Vaghani 22-Dec-22 6:41am    
Don't know that But that is the RGB value of the image
This is so confused no answer is possible. You say that you want to display rgb values when the image changes brightness, but you do nothing to detect brightness change.

Displaying all the pixel rgb values in a textbox makes no sense.

Techniques for finding the brightness of an image: [^].

To detect when overall brightness changes, you will have to loop and compare previous and current brightness.

You need to talk to your teacher and get clarification on what thr assignment really is,

If you did have the average brightness in a textbox, and that was changed to another valid rgb value, then what you woud have to do to change the image brightness is complex: [^]
 
Share this answer
 
v2
Comments
Ridhdhi Vaghani 22-Dec-22 4:20am    
This code does not work. This is my image:- https://ibb.co/7SgXYXL. I mark the RGB value. I want the RGB value like this
BillWoodruff 22-Dec-22 5:38am    
Get your instructor to work with you to figure out what this assignment requires.

The complexity of efficiently altering an image's brightness or contrast can be seen in this complex example:

https://stackoverflow.com/a/3115178/133321

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900