Drawing a QLinearGradient in a QImage
Hi,
I am trying to render a gradient into an image to save it in a file. I am doing this:
- const int histogramSize = 256;
- gradient.setStops(stops);
- p.fillRect(0, 0, histogramSize, 1, gradient);
- const uchar * buffer = lut.bits();
- const int nbOfBytes = histogramSize * 4 ;
- assert(nbOfBytes == lut.byteCount());
- const uchar * endBuffer = buffer + nbOfBytes;
- for(int i = 0 ; i < 2 ; ++i)
- {
- std::cout << i << ": " << color.red() << ' ' << color.green() << ' ' << color.blue() << ' ' << color.alpha() << '\n';
- }
- std::cout << "begin: " << begin.red() << ' ' << begin.green() << ' ' << begin.blue() << ' ' << begin.alpha() << '\n';
- std::cout << "end: " << end.red() << ' ' << end.green() << ' ' << end.blue() << ' ' << end.alpha() << '\n';
And the gradient is defined by two points like you can see in the screenshot
http://s2.postimage.org/7uipuh5it/Screen_Hunter_01_May_13_16_15.jpg
The result of the program is:
0: 252 252 252 2
1: 252 252 252 252
begin: 255 255 255 255
end: 205 205 205 255
However as you can see begin doesn’t have the alpha value I am expecting of them. I tried to change the RGB components and they change properly like I expect them to be but the alpha component never change. It is almost like if the gradient didn’t care on changing the alpha component even if I set the composition mode to source which should basically just dump the gradient into the image. Is it a bug or is it the normal behavior and if it is the normal behavior could someone explain me why?
Thanks
0 replies
You must log in to post a reply. Not a member yet? Register here!
