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

查看:270
本文介绍了如何找到矩形区域内的像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我的图像宽度和高度为1280 * 720。如何查找特定像素包含x0,y0,x1,y1坐标内部



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



将低于algirthm工作


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[1] = { {10, 10, 50, 50}}



这里0表示外部,1表示内部


Here 0 means outside and 1 means inside

推荐答案

是的,它会起作用。但是,出于性能原因,相对较大的 struct s通常通过指针传递(例如,参见 PtInRect Windows函数签名)

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;
}


这篇关于如何找到矩形区域内的像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆