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. Image to bitmap conversion error...again!

Image to bitmap conversion error...again!

Scheduled Pinned Locked Moved C#
questiongraphicshelplinuxdebugging
5 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 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?

    L C H 3 Replies Last reply
    0
    • S sebogawa

      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?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Bitmap bitmap = (Bitmap)image;

      C 1 Reply Last reply
      0
      • L Lost User

        Bitmap bitmap = (Bitmap)image;

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

        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 )

        1 Reply Last reply
        0
        • S sebogawa

          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?

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

          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 )

          1 Reply Last reply
          0
          • S sebogawa

            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?

            H Offline
            H Offline
            Henry Minute
            wrote on last edited by
            #5

            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 both MouseClick and MouseDown of the PictureBox, 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.”

            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