c# - get pixel value greyscale image 16 bits .net -


i have ushort list pixels16 consist in pixeldata 16 bits greyscale image. then, have pícturebox shows image , function user can click anywhere in picturebox , system return pixelvalue position (see below code)

this code return pixel value of given position: in mind, i'm showing value of exact pixel user clicked @ position in image, right?

my logic is, if image 512x512, can go first y once finds spot, go x , pixel value of point this: int pixelposition = (512 * (y-1)) + x;

am in right direction?

        (int y = 0; y < picbox_mpr.width; y++)         {             if (e.y == y)             {                 (int x = 0; x < picbox_mpr.height; x++)                 {                     if (e.x == x)                     {                         int pixelposition = (512 * (y-1)) + x;                         string a= pixels16[pixelposition].tostring();                         messagebox.show(a);                     }                 }             }         } 

for (int y = 0; y < picbox_mpr.width; y++)      {          if (e.y == y)          {              (int x = 0; x < picbox_mpr.height; x++)              {                  if (e.x == x)                  { 

ah, yes, for-if pattern.

this should turned into

int pixelposition = (512 * (e.y-1)) + e.x; string a= pixels16[pixelposition].tostring(); messagebox.show(a); 

with no loops.

you should aware e.x , e.y based on mouse on screen relative top of control, not relative image. it'll little bit wrong in modes due margins, if it's scrolled or scaled or centered it'll wrong. should @ this example code how translate image coordinates.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -