Error in declaring a bitmap as the .image of a picture box
-
I have a function that takes the image in a picture box and converts it to a bitmap (System.Drawing.Image Picturebox.Image to System.Drawing.Bitmap) with the following code:
private void freezeFrame_MouseClick(object sender, MouseEventArgs e)
{
Bitmap refImage = new Bitmap(freezeFrame.Image); //freezeFrame = picture box controlint rangeLimit = 20; txtMouseX.Text = e.X.ToString(); txtMouseY.Text = e.Y.ToString(); int mouseX = int.Parse(txtMouseX.Text); int mouseY = int.Parse(txtMouseY.Text); Color currentPixel = (refImage.GetPixel(mouseX, mouseY)); curPixelRed.Text = currentPixel.R.ToString(); curPixelGreen.Text = currentPixel.G.ToString(); curPixelBlue.Text = currentPixel.B.ToString(); redMinUpDown.Value = currentPixel.R - rangeLimit; redMaxUpDown.Value = currentPixel.R + rangeLimit; greenMinUpDown.Value = currentPixel.G - rangeLimit; greenMaxUpDown.Value = currentPixel.G + rangeLimit; blueMinUpDown.Value = currentPixel.B - rangeLimit; blueMaxUpDown.Value = currentPixel.B + rangeLimit; }
I keep getting an invalid parameter error for the first line of the function. What am I doing wrong?
-
I have a function that takes the image in a picture box and converts it to a bitmap (System.Drawing.Image Picturebox.Image to System.Drawing.Bitmap) with the following code:
private void freezeFrame_MouseClick(object sender, MouseEventArgs e)
{
Bitmap refImage = new Bitmap(freezeFrame.Image); //freezeFrame = picture box controlint rangeLimit = 20; txtMouseX.Text = e.X.ToString(); txtMouseY.Text = e.Y.ToString(); int mouseX = int.Parse(txtMouseX.Text); int mouseY = int.Parse(txtMouseY.Text); Color currentPixel = (refImage.GetPixel(mouseX, mouseY)); curPixelRed.Text = currentPixel.R.ToString(); curPixelGreen.Text = currentPixel.G.ToString(); curPixelBlue.Text = currentPixel.B.ToString(); redMinUpDown.Value = currentPixel.R - rangeLimit; redMaxUpDown.Value = currentPixel.R + rangeLimit; greenMinUpDown.Value = currentPixel.G - rangeLimit; greenMaxUpDown.Value = currentPixel.G + rangeLimit; blueMinUpDown.Value = currentPixel.B - rangeLimit; blueMaxUpDown.Value = currentPixel.B + rangeLimit; }
I keep getting an invalid parameter error for the first line of the function. What am I doing wrong?
Please Update your first line as follows :mad:
Bitmap refImage = new Bitmap((Bitmap)freezeFrame.Image);
Or Convert Image to Bitmap and use this Bitmap as parameter.
©Something Different
-
Please Update your first line as follows :mad:
Bitmap refImage = new Bitmap((Bitmap)freezeFrame.Image);
Or Convert Image to Bitmap and use this Bitmap as parameter.
©Something Different
-
Um.. with the code he gave you to do it ?
Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
-
Um.. with the code he gave you to do it ?
Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
he said that I can do what he told me too or convert the picturebox image to a bitmap...i still get the invalid parameters error when i click on the image ....how do i do the picturebox image to bitmap conversion...i think there is something wrong with my code that is causeing the error
-
I have a function that takes the image in a picture box and converts it to a bitmap (System.Drawing.Image Picturebox.Image to System.Drawing.Bitmap) with the following code:
private void freezeFrame_MouseClick(object sender, MouseEventArgs e)
{
Bitmap refImage = new Bitmap(freezeFrame.Image); //freezeFrame = picture box controlint rangeLimit = 20; txtMouseX.Text = e.X.ToString(); txtMouseY.Text = e.Y.ToString(); int mouseX = int.Parse(txtMouseX.Text); int mouseY = int.Parse(txtMouseY.Text); Color currentPixel = (refImage.GetPixel(mouseX, mouseY)); curPixelRed.Text = currentPixel.R.ToString(); curPixelGreen.Text = currentPixel.G.ToString(); curPixelBlue.Text = currentPixel.B.ToString(); redMinUpDown.Value = currentPixel.R - rangeLimit; redMaxUpDown.Value = currentPixel.R + rangeLimit; greenMinUpDown.Value = currentPixel.G - rangeLimit; greenMaxUpDown.Value = currentPixel.G + rangeLimit; blueMinUpDown.Value = currentPixel.B - rangeLimit; blueMaxUpDown.Value = currentPixel.B + rangeLimit; }
I keep getting an invalid parameter error for the first line of the function. What am I doing wrong?
Hi, several comments: 1.
sebogawa wrote:
txtMouseX.Text = e.X.ToString(); int mouseX = int.Parse(txtMouseX.Text);
What a waste. You already have e.X as a number, why do you need to parse a string then. Just write
int mouseX = e.X;
txtMouseX.Text = mouseX.ToString();2.
Bitmap refImage = new Bitmap(freezeFrame.Image);
You claim the problem is here, I doubt that. There are two ways this could fail: a) freezeFrame.Image being null would result in a NullReferenceException b) freezeFrame.Image being of some special ImageFormat (such as EMF) might cause problems, I'm not sure though. 3.Color currentPixel = (refImage.GetPixel(mouseX, mouseY));
would throw an ArgumentOutOfRangeException when mouseX and/or mouseY fall outside the image. 4.redMinUpDown.Value = currentPixel.R - rangeLimit;
may cause problems since the lowest achievable value is negative (-rangeLimit). If Value is set outside [Minimum,Maximum] an ArgumentOutOfRangeException will be thrown. Overall, your code is low-quality as it lacks a lot of checks. :)Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in