如何解决向GDI +位图添加一定百分比的噪声失败
我已经编写了这段代码,该代码生成一个像素矢量,以“ noise”设置。问题是无论我做什么,我只会得到一条NW-SE线。不是随机的点。我在做什么错了?
void CPixelNoiseGenerator::GeneraterandomNoise(NoiseAmount eNoiseAmount,UINT nNoiseAmount,UINT nWidth,UINT nHeight,std::vector<CPoint>& vecPoints)
{
unsigned long long nNumPixels = nWidth * nHeight,nNumNoisePixels = 0;
nNumNoisePixels = (nNumPixels * nNoiseAmount) / 100;
vecPoints.clear();
if (nNumNoisePixels == 0)
return;
UINT nWidthdistance = (nWidth * nNoiseAmount) / 100,nHeightdistance = (nHeight * nNoiseAmount) / 100;
std::random_device rd;
std::mt19937 generator(rd());
std::uniform_real_distribution<> distribution(0.0,(nWidth < nHeight ? nHeightdistance : nWidthdistance) * 1.0);
auto dice = std::bind(distribution,generator);
do
{
for(UINT x = 0; x < nWidth; x += nWidthdistance)
for (UINT y = 0; y < nHeight; y += nHeightdistance)
{
CPoint pt; // = GetRandomPointOnDesign(nWidth,nHeight,generator);
pt.x = x + distribution(generator);
pt.y = y + distribution(generator);
vecPoints.push_back(pt);
}
} while (vecPoints.size() <= nNumNoisePixels);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。