QImage灰度和亮度处理
下面是两个处理函数QImage* ImageProcessor::greyScale(QImage *origin){ QImage * newImage = new QImage(origin->width(), origin->height(), QImage::Format_ARGB32); QColor oldColor; for(int x = 0; xwidth(); x++){ for(int y = 0; yheight(); y++){ oldColor = QColor(origin->pixel(x,y)); int average = (oldColor.red()+oldColor.green()+oldColor.blue())/3; newImage->setPixel(x,y,qRgb(average,average,average)); } } return newImage;}QImage * ImageProcessor::brightness(int delta, QImage * origin){ QImage * newImage = new QImage(origin->width(), origin->height(), QImage::Format_ARGB32); QColor oldColor; int r,g,b; for(int x=0; xwidth(); x++){ for(int y=0; yheight(); y++){ oldColor = QColor(origin->pixel(x,y)); r = oldColor.red() + delta; g = oldColor.green() + delta; b = oldColor.blue() + delta; //we check if the new values are between 0 and 255 r = qBound(0, r, 255); g = qBound(0, g, 255); b = qBound(0, b, 255); newImage->setPixel(x,y, qRgb(r,g,b)); } } return newImage;}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~