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

网站开发大概多久wordpress 教育

网站开发大概多久,wordpress 教育,最新商业资讯,外贸网站什么采集由于项目需要&#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/805517/

相关文章:

  • 深圳网站建设qwyx100dz网站恢复数据库
  • wap网站解析专业网站优化
  • 长沙网站优化分析建设网站必备的三大要素
  • 做项目的网站绍兴网站开发公司
  • 公司怎么注册网站免费移动端网站建设的尺寸
  • 建设银行网站短信错误6次快普网站怎么做采购退货
  • 花店商城网站设计wordpress 注册表单
  • 单网页网站内容目前网站在初级建设阶段_需要大量数据丰富
  • 科讯cms 3g 网站设置专业网站建设品牌策划
  • 兰州学校网站建设网站域名如何影响seo
  • 邯郸网站建设维护李宁运动服网站建设规划书
  • 中国建设银行人才招聘网站山东网站建设哪家有
  • 电子商务网站总体规划的内容展厅设计施工
  • 新闻录入网站模板购物网站支付功能怎么做
  • mui做浏览器网站跳转墨客网站建设
  • 用树莓派做网站服务器lamp网站开发制作
  • 苏州外贸网站推广建设个网站
  • 百度快照推广排名惠州百度搜索优化
  • 网站建设电销话术开场白电子商务网站建设实训报告范文
  • 网站的轮播图怎么做app软件商店
  • 用php做的录入成绩的网站海口专业做网站
  • 网站设计制作全网优惠用dw做网站用什么主题比较好
  • 在家建设一个网站需要什么材料网站短链接生成
  • 深圳网站开发制作官网登录入口在哪里
  • 手游门户网站建设广州有什么互联网公司
  • 宝塔建站详细教程wordpress+站群软件
  • 硅胶东莞网站建设深圳品牌营销推广
  • 网站常用代码做欧美贸易的主要有哪些网站
  • 注销主体备案与网站备案表无锡企业自助建站系统
  • 建设网站桫椤在室内能办公室装修会计分录