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

镇江企业网站网上在哪里打广告最有效

镇江企业网站,网上在哪里打广告最有效,wordpress搬家csdn,郓城网站开发由于项目需要&#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.wangmingla.cn/news/101325.html

相关文章:

  • 网站优化都是怎么做的人工智能培训班收费标准
  • 网站建设教育培训无锡seo公司
  • 广州网站建设定制设计软文营销名词解释
  • 电子商务网站页面设计图片提高工作效率心得体会
  • 群晖nas做网站做网页用什么软件好
  • 精美图片做网站上哪儿去找图百度seo优化招聘
  • 成都网站排名优化报价现在推广平台哪家最好
  • 男女性做那个微视频网站广州知名网络推广公司
  • 建立外贸英文网站应该怎么做软件开发公司推荐
  • 免费ppt下载网站网站推广工具有哪些
  • 杭州怎么做网站免费域名申请个人网站
  • 2021年中央农村工作会议推广优化排名
  • 我谁知道在哪里可以找人帮忙做网站云南今日头条新闻
  • 电商平台门户网站建设的重要性重庆seo排名扣费
  • 兼职做一篇微信的网站网推拉新app推广接单平台
  • 网络营销的步骤和流程贵州seo学校
  • 手机网站滑动效果电商运营培训课程有哪些
  • 做网站的语广告投放都有哪些平台
  • 电子商务网站建设的核心是什么免费友情链接交换平台
  • 家居定制类网站建设搜索引擎关键词优化技巧
  • 手机网站应该怎么做项目推广平台排行榜
  • 抽奖网站开发网络营销工资一般多少
  • 网站搭建设计 是什么如何网页优化
  • 快捷网站建设互联网服务平台
  • 惠阳网站开发2022重大时政热点事件简短
  • 新疆网站建设制作天津放心站内优化seo
  • 南昌专门做网站免费广告发布平台
  • 专门做游戏交易的网站有哪些自动优化句子的软件
  • 保定干洗机做网站seo优化专员
  • 旧房改造室内装修设计公司关键词优化是什么意思