c# - Getting a pixel's color from an image in a picturebox is not working -


i trying make windows form application. in application there picture box, , user can choose color clicking on color within picture.

so googled , tried things, not working correctly,

so have code checking on point user clicks within picture box , setting r, g , b:

    private void picturebox1_click(object sender, eventargs e)     {         x = mouseposition.x;         y = mouseposition.y;         messagebox.show(string.format("x: {0} y: {1}", x, y));          coloratpoint = properties.resources.kleuren_rondje.getpixel(x, y);          r = coloratpoint.r;         g = coloratpoint.g;         b = coloratpoint.b;              } 

and have check color

        private void colorchecker()     {         graphics e = picturebox2.creategraphics();         solidbrush mybrush = new solidbrush(color.fromargb(r, g, b));          e.fillrectangle(mybrush, 1, 1, 100, 100);     } 

and checking if color found en add in other picture box (for testing)

        private void button1_click(object sender, eventargs e)     {         colorchecker();                 } 

i used methods internet r, g , b still gives 255. knows why or maybe other way check r,g,b picture on clicked point.

btw, x , y gives point locations

regards

mouseposition returns screen coords. need client coords.

either convert it:

        point pt = picturebox1.pointtoclient(mouseposition);         x = pt.x;         y = pt.y; 

...or use mousedown() , corresponding e.x , e.y:

    private void picturebox1_mousedown(object sender, mouseeventargs e)     {         x = e.x;         y = e.y;         messagebox.show(string.format("x: {0} y: {1}", x, y));          // ...      } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -