当前位置: 首页 > news >正文

网站打不开 ...济南网站假设推广

网站打不开 ...,济南网站假设推广,常州百度搜索优化,药品彩页设计由于项目需要&#xff0c;需生成一幅纯马赛克的图像作为背景&#xff0c;经过多次测试成功&#xff0c;记录下来。 方法一&#xff1a;未优化方法 1、代码&#xff1a; #include <QImage> #include <QDebug> #include <QElapsedTimer>QImage generateMosa…

由于项目需要,需生成一幅纯马赛克的图像作为背景,经过多次测试成功,记录下来。

方法一:未优化方法

1、代码:

#include <QImage>
#include <QDebug>
#include <QElapsedTimer>QImage generateMosaic(int width, int height, int blockSize) {QImage image(width, height, QImage::Format_RGB888);if (blockSize <= 0) {return QImage(); // 返回空图片或处理错误}// 确保blockSize是偶数,并且不会使图像尺寸变得太小blockSize = (blockSize % 2 == 0) ? blockSize : blockSize + 1;if (image.width() < blockSize || image.height() < blockSize) {return image; // 如果blockSize太大,直接返回原图}// 计算新图片的尺寸int newWidth = image.width() / blockSize * blockSize;int newHeight = image.height() / blockSize * blockSize;qDebug() << "newWidth = " << newWidth << ", newHeight = " << newHeight;//QImage newImage(newWidth, newHeight, image.format());// 遍历每个块for (int x = 0; x < newWidth; x += blockSize) {for (int y = 0; y < newHeight; y += blockSize) {// 计算块的平均颜色QColor averageColor = QColor(0, 0, 0); // 初始化平均颜色为黑色// 用平均颜色填充整个块if((y / blockSize) % 2 == 0) {if((x/blockSize) % 2 == 0) {averageColor = QColor(60,60,60);} else {averageColor = QColor(150,150,150);}} else {if((x/blockSize) % 2 == 0) {averageColor = QColor(150,150,150);} else {averageColor = QColor(60,60,60);}}for  (int bx = 0; bx < blockSize && x + bx < newWidth; ++bx) {for ( int by = 0; by < blockSize && y + by < newHeight; ++by) {image.setPixel(x+bx, y+by, qRgb(averageColor.red(), averageColor.blue(), averageColor.green()));}}}}return image;
}int main()
{QElapsedTimer elapsed_timer; elapsed_timer.start(); QImage mosicImage = generateMosaic(1280,960,40);qDebug() << "Used" << elapsed_timer.elapsed() << "milliseconds.";mosicImage.save("mosic.jpg");return 0;
}

2、效果:

运行结果

newWidth =  1280 , newHeight =  960
Used 19 milliseconds.

方法二:优化后方法

更优化的方法:

1、代码

#include <QImage>
#include <QDebug>
#include <QPainter>
#include <QElapsedTimer>QImage generateMosaic(int width, int height, QImage::Format format)
{QColor color_a(102, 102, 102); QColor color_b(128, 128, 128);QImage empty_image(width, height, format);empty_image.fill(color_a);QPainter empty_painter(&empty_image);int stride = 32;for (int i=0; i<empty_image.width(); i+=stride) {for (int j=0; j<empty_image.height(); j+=stride) {if ((i+j) % (2*stride) == 0) {empty_painter.fillRect(QRect(i, j, stride, stride), color_b);} else {empty_painter.fillRect(QRect(i, j, stride, stride), color_a);}}}return empty_image;
}int main()
{QElapsedTimer elapsed_timer; elapsed_timer.start(); QImage mosicImage = generateMosaic(1280,960,QImage::Format_RGB888);qDebug() << "Used" << elapsed_timer.elapsed() << "milliseconds.";mosicImage.save("mosic.jpg");return 0;
}

2、效果

运行效果

Used 4 milliseconds.

http://www.yayakq.cn/news/297122/

相关文章:

  • 福田做网站公司怎么选择seo专业培训
  • 南昌网站建设方案开发app开发全过程
  • 网站模板更换如何在百度网站收录提交入口
  • 做网站 页面自适应怎么用腾讯云主机建设网站
  • 村镇建设年度报表登录网站自建网站平台
  • 如何做天猫网站海阳市最新新闻热点
  • 苏州大型网站建设卡一卡二卡三入口2021
  • 衡水高端网站建设电脑wordpress
  • 网站用什么颜色旅游扁平化设计网站模板
  • 蛋糕方案网站建设wordpress下载类模板下载
  • 长春市城乡建设部网站wordpress地图
  • 太原网站seo外包-1网站建设
  • 苏州新区网站建设南昌那个公司做网站好
  • wordpress 网站打不开wordpress添加新页面
  • 新泰网站建设方案苏州企业网站开发
  • 像饿了码的网站建站有吗环影视界免费版wordpress主题
  • 做网站的功能是什么福山区建设工程质量检测站网站
  • wordpress 建站免费网页版梦幻西游哪个职业厉害
  • 深圳罗湖网站制作公司公司网站做的一样算不算侵权6
  • 大石桥网站建设wordpress 音乐主题模板
  • 金昌做网站网游排行榜2021前十名
  • 广西柳州网站建设小程序公司wordpress标签后多了一个()
  • 宝安建设网站免费源码网站
  • 兰州百姓网免费发布信息网站3e网站建设
  • 国外免费源码网站网站的logo怎么换
  • 百度网站权重找网络公司做网站需要注意什么
  • 提供网站建设价格wordpress auto tags
  • 馆陶网站建设电话青岛高端模板建站
  • 舞蹈网站模版网站色彩
  • 网站管理更新维护做cpa广告网站教程