计算CRgn对象内的像素数 [英] Count no of pixels inside a CRgn object

查看:121
本文介绍了计算CRgn对象内的像素数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算CRgn对象中的像素数?
一种方法是获取区域的边界矩形,然后检查边界矩形中的每个像素是否位于CRgn内.
此方法需要更多时间,并且取决于CRgn对象的大小.
是否还有其他方法可以计算出CRgn对象内部的像素数,而该方法花费的时间更少,并且不取决于CRgn对象的大小?
在此先感谢您.

How to count number of pixels inside a CRgn object?
One method is to get the bounding rect of the region and then checking for each pixel in the bounding rect whether it lies inside the CRgn or not.
This method takes more time and it depends on the size of CRgn object.
Is there any other method to calculate the number of pixel inside CRgn object which takes less time and which is not dependent on the size of CRgn object?
Thanks in advance.

推荐答案

下面是用于计算CRgn中像素数量的代码

Below is the code for calculating the number of pixel inside CRgn

int nNumberOfPixel = 0;
int nSize = m_pROIRgn->GetRegionData(NULL, NULL);
if(nSize)
{
    RGNDATA * pRegion = (RGNDATA *) new char[nSize];
    m_pROIRgn->GetRegionData(pRegion, nSize);
    const RECT* pRect = (const RECT *) & pRegion->Buffer;
    int rectcount = pRegion->rdh.nCount;
    for(int i = 0; i < rectcount; i++)
    {
        nNumberOfPixel = nNumberOfPixel + ((pRect[ i ].right - pRect[ i ].left) * (pRect[ i ].bottom - pRect[ i ].top));
    }
    delete [] (char *) pRegion;
}



感谢CPallini和YDaoust的帮助.



Thanks CPallini and YDaoust for help.


您可以致电 ^ ]方法,然后使用 RGDNDATAHEADER [ ^ ]和 RGNDATA [
You may call GetRegionData[^] method and then use the RGDNDATAHEADER[^] and RGNDATA[^] info to compute the number of pixel in the rectangles composing the region (just a guess, I didn''t test it).


我支持CPallini所说的话.您可以将区域分解为矩形.总面积是所有这些矩形的宽度x高度之和.

与查询每个像素相比,这将非常快. (时间与行数成正比,如果区域很简单,则更少.)
I support what CPallini says. You can retrieve a region as a decomposition into rectangles. The total area is the sum of width x height for all these rectangles.

This will be very fast compared to querying every pixel. (Time proportional to the number of rows, or even less if the regions are simple.)


这篇关于计算CRgn对象内的像素数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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