Qt/C++ 改变图片亮度算法 注意是算法

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; yheight(); ++y)
{
for(int x=0; xwidth(); ++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;  

}

总体思路就是获取每一个像素点,再通过一个什么什么算法计算出该出该像素的值,再重新设置该像素点的值,差不多就是这样

powered by:小乌龟在大乌龟背上
文章来源:http://blog.csdn.net/what951006

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值