c++ - 向 GDI+ 位图添加一定百分比的噪点失败
问题描述
我编写了这段代码,它生成一个像素向量以设置“噪声”。问题是无论我做什么,我只得到一条 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);
}
解决方案
推荐阅读
- docker - Docker windows 容器和“npm 未被识别为内部或外部命令”
- utf-8 - 带有特殊字符的主题错误,通过 openssl 和 s_client 发送电子邮件 SMPT
- r - 如何在 R 中创建不打印属性(不复制对象)的打印方法?
- java - 尝试创建新对象时出现未知类错误
- reactjs - 组件渲染后的第二个生命周期是什么?- 反应 Js
- python - 一旦用户单击按钮并提交并提交,Tkinter 就会向他们显示用户的选择
- java - JTable 从 DataModel 更改单元格背景颜色
- swift - 无法使用包含二进制目标 (xcframework) 的 Swift 包归档项目
- android - 如何使用 Picasso 将 imageView 中包含的图像保存到内部存储
- python - 登录屏幕在页面上不显示任何内容