Image to bitmap conversion error...again!
-
I have the following two functions:
private void freezeFrame\_MouseClick(object sender, MouseEventArgs e) { txtMouseX.Text = e.X.ToString(); txtMouseY.Text = e.Y.ToString(); getPixel(); } private void getPixel() { int rangeLimit = 20; int mouseX = int.Parse(txtMouseX.Text); int mouseY = int.Parse(txtMouseY.Text); Bitmap refBitmap = null; System.Drawing.Image refImage = null; refImage = freezeFrame.Image; refBitmap = new Bitmap(refImage); Color currentPixel = (refBitmap.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; }
when i run the code, and click on the picturebox i get the following error "ArgumentException was unhandeled" with the statement "Parameter is not valid" for the line refBitmap = new Bitmap(refImage). I tried changing up the way i declare the refImage and refBitmap as suggested by people on my previous question and nothing works. What should I do? When I debug, the Locals are as follows: rangeLimit = 20 mouseX = 70 (red) mouseY = 91 (red) reBitmap = null refImage = {System.Drawing.Bitmap} currentPixel = "{Name=0, ARGB=(0,0,0,0)}" Is there a direct way to convert a System.Drawing.Image to System.Drawing.Bitmap? I tried what someone else instructed me to do and I keep getting the same error and if I ask this question again, people just bash me on the fact that the code is low quality or other non-constructive criticism. All i need is to figure out what is wrong with my code, not a lecture on why i suck as a programmer. We all start somewhere and we all make mistakes but I digress. Can anyone help me solve this dilemma?
-
I have the following two functions:
private void freezeFrame\_MouseClick(object sender, MouseEventArgs e) { txtMouseX.Text = e.X.ToString(); txtMouseY.Text = e.Y.ToString(); getPixel(); } private void getPixel() { int rangeLimit = 20; int mouseX = int.Parse(txtMouseX.Text); int mouseY = int.Parse(txtMouseY.Text); Bitmap refBitmap = null; System.Drawing.Image refImage = null; refImage = freezeFrame.Image; refBitmap = new Bitmap(refImage); Color currentPixel = (refBitmap.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; }
when i run the code, and click on the picturebox i get the following error "ArgumentException was unhandeled" with the statement "Parameter is not valid" for the line refBitmap = new Bitmap(refImage). I tried changing up the way i declare the refImage and refBitmap as suggested by people on my previous question and nothing works. What should I do? When I debug, the Locals are as follows: rangeLimit = 20 mouseX = 70 (red) mouseY = 91 (red) reBitmap = null refImage = {System.Drawing.Bitmap} currentPixel = "{Name=0, ARGB=(0,0,0,0)}" Is there a direct way to convert a System.Drawing.Image to System.Drawing.Bitmap? I tried what someone else instructed me to do and I keep getting the same error and if I ask this question again, people just bash me on the fact that the code is low quality or other non-constructive criticism. All i need is to figure out what is wrong with my code, not a lecture on why i suck as a programmer. We all start somewhere and we all make mistakes but I digress. Can anyone help me solve this dilemma?
-
This obviously won't work.
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 )
-
I have the following two functions:
private void freezeFrame\_MouseClick(object sender, MouseEventArgs e) { txtMouseX.Text = e.X.ToString(); txtMouseY.Text = e.Y.ToString(); getPixel(); } private void getPixel() { int rangeLimit = 20; int mouseX = int.Parse(txtMouseX.Text); int mouseY = int.Parse(txtMouseY.Text); Bitmap refBitmap = null; System.Drawing.Image refImage = null; refImage = freezeFrame.Image; refBitmap = new Bitmap(refImage); Color currentPixel = (refBitmap.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; }
when i run the code, and click on the picturebox i get the following error "ArgumentException was unhandeled" with the statement "Parameter is not valid" for the line refBitmap = new Bitmap(refImage). I tried changing up the way i declare the refImage and refBitmap as suggested by people on my previous question and nothing works. What should I do? When I debug, the Locals are as follows: rangeLimit = 20 mouseX = 70 (red) mouseY = 91 (red) reBitmap = null refImage = {System.Drawing.Bitmap} currentPixel = "{Name=0, ARGB=(0,0,0,0)}" Is there a direct way to convert a System.Drawing.Image to System.Drawing.Bitmap? I tried what someone else instructed me to do and I keep getting the same error and if I ask this question again, people just bash me on the fact that the code is low quality or other non-constructive criticism. All i need is to figure out what is wrong with my code, not a lecture on why i suck as a programmer. We all start somewhere and we all make mistakes but I digress. Can anyone help me solve this dilemma?
This is terrible code. Very inefficient. Is GetPixel a method in the Bitmap class and not Image ? This will make your code even less efficient, but the way to do it is Bitmap b = new Bitmap(myImage);
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 )
-
I have the following two functions:
private void freezeFrame\_MouseClick(object sender, MouseEventArgs e) { txtMouseX.Text = e.X.ToString(); txtMouseY.Text = e.Y.ToString(); getPixel(); } private void getPixel() { int rangeLimit = 20; int mouseX = int.Parse(txtMouseX.Text); int mouseY = int.Parse(txtMouseY.Text); Bitmap refBitmap = null; System.Drawing.Image refImage = null; refImage = freezeFrame.Image; refBitmap = new Bitmap(refImage); Color currentPixel = (refBitmap.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; }
when i run the code, and click on the picturebox i get the following error "ArgumentException was unhandeled" with the statement "Parameter is not valid" for the line refBitmap = new Bitmap(refImage). I tried changing up the way i declare the refImage and refBitmap as suggested by people on my previous question and nothing works. What should I do? When I debug, the Locals are as follows: rangeLimit = 20 mouseX = 70 (red) mouseY = 91 (red) reBitmap = null refImage = {System.Drawing.Bitmap} currentPixel = "{Name=0, ARGB=(0,0,0,0)}" Is there a direct way to convert a System.Drawing.Image to System.Drawing.Bitmap? I tried what someone else instructed me to do and I keep getting the same error and if I ask this question again, people just bash me on the fact that the code is low quality or other non-constructive criticism. All i need is to figure out what is wrong with my code, not a lecture on why i suck as a programmer. We all start somewhere and we all make mistakes but I digress. Can anyone help me solve this dilemma?
I have just created a test project and pasted your code into it. It works perfectly. So, question. What event are you handling with
freezeFrame_MouseClick
? You see I tried it with bothMouseClick
andMouseDown
of thePictureBox
, and it worked for both.Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”