QColor color; QImage *image; QSvgRenderer* svg;
svg = new QSvgRenderer(); image = 0;
svg->load( shapefilename ); // где (QString) shapefilename - имя файла с полным маршрутом в ресурсах
void MyLED::paintLED(){ if( image ) delete image; QImage* image = new QImage(size(), QImage::Format_ARGB32_Premultiplied); image->fill(0); QPainter p( image ); p.setRenderHint(QPainter::Antialiasing, true); svg->render( &p ); int i, j, w = image->width(), h = image->height(); for( i = 0; i < w; i++ ) for( j = 0; j < h; j++ ) { float percent = (float)qBlue(image->pixel(i,j)) / 255; // все каналы одинаковые, но синий самый дешевый int r = color.red() * percent, g = color.green() * percent, b = color.blue() * percent; image->setPixel(i,j, qRgba(r,g,b,qAlpha(image->pixel(i,j))) ); } update();}
void MyLED::paintEvent(QPaintEvent *){ QPainter p(this); p.drawImage(0,0,*image);}
delete image; delete svg;
void MyLED::paintLED(){ if( image ) delete image; QImage* image = new QImage(size(), QImage::Format_ARGB32_Premultiplied); image->fill(0); QPainter p( image ); p.setRenderHint(QPainter::Antialiasing, true); svg->render( &p ); int i, j, w = image->width(), h = image->height(); for( i = 0; i < w; i++ ) for( j = 0; j < h; j++ ) { float percent = (float)qBlue(image->pixel(i,j)) / 256; int r = color.red() * percent, g = color.green() * percent, b = color.blue() * percent; image->setPixel(i,j, qRgba(r,g,b,qAlpha(image->pixel(i,j))) ); } update();}
int gray = qBlue(image->pixel(i,j));#define SPOT 180 if( gray < SPOT ) { float percent = (float)gray / SPOT; image->setPixel(i,j, qRgba( color.red() * percent, color.green() * percent, color.blue() * percent, qAlpha(image->pixel(i,j)) )); } else { float percent = ((float)gray - SPOT) / (256 - SPOT); image->setPixel(i,j, qRgba( color.red() + (255 - color.red()) * percent, color.green() + (255 - color.green()) * percent, color.blue() + (255 - color.blue()) * percent, qAlpha(image->pixel(i,j)) )); }