# 如何找到矩形区域内的像素(How to find a pixel which is inside rectangular area or not)

79 IT屋

For eg i have a image of 1280*720 width and height. How to find a particular pixel contains inside x0,y0,x1,y1 co-ordinate

```x0,y0
+--------+
|        |
|        |
|     .  |
|        |
|        |
+--------+x1,y1```

Will below algirthm work
```typedef struct {
int left;
int top;
int right;
int bot;
} rect;

int inrect (int x, int y, rect r) {
if (x<r.left || x>r.right || y<r.top || y>r.bot)
return 0;
return 1;
}
rect rectarr = { {10, 10, 50, 50}}```

Here 0 means outside and 1 means inside

Yes, it would work. However, for performance reasons, relatively big structs are usually passed via pointers (see, for instance, PtInRect Windows function signature)
```int inrect (int x, int y, const rect *pr) {
if (x<pr->left || x>pr->right || y<pr->top || y>pr->bot)
return 0;
return 1;
}```

` x0，y0  + -------- +  | |  | |  | 。 |  | |  | |  + -------- + x1，y1 `

` typedef  struct  {  int  left;   int  top;   int  right;   int  bot; } rect;    int  inrect（ int  x， int  y，rect r）{  if （x< r.left || x> r.right || y< r .top || y> r.bot）  return   0 ;   return   1 ; }  rect rectarr [ 1 ] = {{ 10 ， 10 ， 50 ， 50 }} `

`  int  inrect（ int  x， int  y， const  rect * pr）{  if （x< pr-> left || x> pr-> right || y< pr-> top || y> pr-> bot）  return   0 ;   return   1 ; } `