Qt 改变图片亮度算法
2015-10-08 22:03
423 查看
QImage Bright1(QImage &image,int brightness) { uchar *line =image.scanLine(0); uchar *pixel = line; for (int y = 0; y < image.height(); ++y) { pixel = line; for (int x = 0; x < image.width(); ++x) { *pixel = qBound(0, *pixel + brightness, 255); *(pixel + 1) = qBound(0, *(pixel + 1) + brightness, 255); *(pixel + 2) = qBound(0, *(pixel + 2) + brightness, 255); pixel += 4; } line += image.bytesPerLine(); } return image; } QImage Bright2(QImage &image,int brightness) { QImage origin = image; QColor oldColor; int delta = brightness; int r=0,g=0,b=0; uchar *line =image.scanLine(0); uchar *pixel = line; QImage * newImage = new QImage(origin.width(), origin.height(), QImage::Format_ARGB32); for(int y=0; y<newImage->height(); ++y) { for(int x=0; x<newImage->width(); ++x) { oldColor = QColor(image.pixel(x,y)); r = oldColor.red() + brightness; g = oldColor.green() + brightness; b = oldColor.blue() + brightness; newImage->setPixel(x,y, qRgb(r,g,b)); } } return *newImage; } QImage Bright3(QImage& source, int factor) { if (factor < -255 || factor > 255) return source; int red, green, blue; int pixels = source.width() * source.height(); unsigned int *data = (unsigned int *)source.bits(); for (int i = 0; i < pixels; ++i) { red= qRed(data[i])+ factor; red = (red < 0x00) ? 0x00 : (red > 0xff) ? 0xff : red; green= qGreen(data[i])+factor; green = (green < 0x00) ? 0x00 : (green > 0xff) ? 0xff : green; blue= qBlue(data[i])+factor; blue = (blue < 0x00) ? 0x00 : (blue > 0xff) ? 0xff : blue ; data[i] = qRgba(red, green, blue, qAlpha(data[i])); } return source; }
相关文章推荐
- QT学习 第一章:基本对话框
- 使用Shiboken为C++和Qt库创建Python绑定
- Qt定时器和随机数详解
- Qt实现图片移动实例(图文教程)
- Qt for Android开发实例教程
- QModelIndex/Role/Model介紹<二>
- 基于PyQt5的快速开发框架QFramer
- OSX下安装PyQt
- ok6410开发板移植DirectFB手记
- 【笔记】给Qt内嵌一个Chrome吧
- 【算法】最短路径之A*搜索
- qt入门必备
- 在 Qt4 中使用 C++11
- Hello Word ~ v0.2.2 背单词软件发布 -- By WHYPRO
- ubuntu下opencv和qt的安装配置
- linux下opengl的安装(with qt)
- qt 学习小节
- QT的命名风格
- QT 中的sleep
- QT 串口的监控