Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Error in declaring a bitmap as the .image of a picture box

Error in declaring a bitmap as the .image of a picture box

Scheduled Pinned Locked Moved C#
graphicshelpquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sebogawa
    wrote on last edited by
    #1

    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 control

            int 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?

    S L 2 Replies Last reply
    0
    • S sebogawa

      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 control

              int 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?

      S Offline
      S Offline
      Sibugathulla
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • S Sibugathulla

        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

        S Offline
        S Offline
        sebogawa
        wrote on last edited by
        #3

        How can I convert the image? Sorry for the noobish question...

        C 1 Reply Last reply
        0
        • S sebogawa

          How can I convert the image? Sorry for the noobish question...

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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 )

          S 1 Reply Last reply
          0
          • C Christian Graus

            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 )

            S Offline
            S Offline
            sebogawa
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • S sebogawa

              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 control

                      int 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?

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              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


              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups